Saturday, September 18, 2010

Why unhandled exceptions can be good

There are always going to be scenarios in a piece of software that the developers haven't thought of, causing serious issues in the application.  Sometimes these issues can be caused by faulty software, but they can also be caused by corrupt data, corrupt files, problems with the operating system, etc.  If one of these issues causes the application to crash, it is generally called an unhandled exception.

Unhandled exceptions can make software users nervous about the quality of their software, and so software developers rightly try to avoid them.  This idea can be taken too far, though.  I have worked on a few applications where the developers involved tried to avoid showing the user an unhandled exception at all costs.  However, that meant that there were times when something went wrong, the error was swallowed by the software, and the user was never notified.  This can often result in messy data.  To see why, consider this scenario:

A doctor at a hospital is entering her patient's medication information in the computer to monitor the patient's medication types and amounts to prevent over-dosage and dangerous drug interactions.  This patient has just been administered three drugs.  In entering the information, the application has unforeseen problems with medication #2.  If the error allows the application to crash, the doctor will know that something has gone wrong and will restart the application to see what information will need to be reentered.  This is annoying for the doctor, but is not life-threatening.  If instead the application had swallowed the exception, and either gave the doctor a cryptic message or no message at all (which is sadly often the case), the doctor will have no idea to go into the system and double-check those entries.  I can only imagine the problems that can be caused by incorrect medication information being stored for a patient.

So what does this mean for you?  If you are on the implementation side, do not give into the temptation to bubble-wrap your application to the point where unhandled exceptions can never occur.  Certainly handle the exceptions you can foresee.  Your users will rightly expect this.  But do not hide problems to the extent that no one can tell they occurred, or that the user does not understand the severity of the error.  Finally, be sure that you are notified through an automatic e-mail or similar measure if such an error arises.  If you are a user, do not overreact when such an error occurs to you.  It is certainly frustrating to have your software application quit on you, but keep the alternative in mind.  At least you know something went badly wrong.

No comments:

Post a Comment