Exception Handling - Exception Handling in Software

Exception Handling in Software

Software exception handling and the support provided by software tools differs somewhat from what is understood under exception in hardware, but similar concepts are involved. In programming language mechanisms for exception handling, the term exception is typically used in a specific sense to denote a data structure storing information about an exceptional condition. One mechanism to transfer control, or raise an exception, is known as a throw. The exception is said to be thrown. Execution is transferred to a "catch".

From the point of view of the author of a routine, raising an exception is a useful way to signal that a routine could not execute normally - for example, when an input argument is invalid (e.g. value is outside of the domain of a function) or when a resource it relies on is unavailable (like a missing file, a hard disk error, or out-of-memory errors). In systems without exceptions, routines would need to return some special error code. However, this is sometimes complicated by the semipredicate problem, in which users of the routine need to write extra code to distinguish normal return values from erroneous ones.

Exception handling mechanisms in contemporary languages are typically non-resumable ("termination semantics") as opposed to hardware exceptions that are typically resumable. On the rationale for such a design for the C++ mechanism, Stroustrup notes: "At the Palo Alto meeting in November 1991, we heard a brilliant summary of the arguments for termination semantics backed with both personal experience and data from Jim Mitchell (from Sun, formerly from Xerox PARC). Jim had used exception handling in half a dozen languages over a period of 20 years and was an early proponent of resumption semantics as one of the main designers and implementers of Xerox's Cedar/Mesa system. His message was termination is preferred over resumption; this is not a matter of opinion but a matter of years of experience. Resumption is seductive, but not valid. He backed this statement with experience from several operating systems. The key example was Cedar/Mesa: It was written by people who liked and used resumption, but after ten years of use, there was only one use of resumption left in the half million line system -- and that was a context inquiry. Because resumption wasn't actually necessary for such a context inquiry, they removed it and found a significant speed increase in that part of the system. In each and every case where resumption had been used it had -- over the ten years -- become a problem and a more appropriate design had replaced it. Basically, every use of resumption had represented a failure to keep separate levels of abstraction disjoint."

Contemporary applications face many design challenges when considering exception handling strategies. Particularly in modern enterprise level applications, exceptions must often cross process boundaries and machine boundaries. Part of designing a solid exception handling strategy is recognizing when a process has failed to the point where it cannot be economically handled by the software portion of the process.

Read more about this topic:  Exception Handling

Famous quotes containing the words exception and/or handling:

    For a parent, it’s hard to recognize the significance of your work when you’re immersed in the mundane details. Few of us, as we run the bath water or spread the peanut butter on the bread, proclaim proudly, “I’m making my contribution to the future of the planet.” But with the exception of global hunger, few jobs in the world of paychecks and promotions compare in significance to the job of parent.
    Joyce Maynard (20th century)

    Mothers risk alienating their mates if they expect them to hold or care for the baby exactly as they do. Fathers who are constantly criticized or corrected may lose interest in handling the baby, and this is a loss for everyone. The cycle is a dangerous one. Now the same mother feels bitter because she is no longer getting any help at home.
    Cathy Rindner Tempelsman (20th century)