Page 375 -
P. 375
358 Chapter 13 Dependability engineering
Code Section
Normal Flow
of Control
Exception Detected
Normal Exit
Exception
Processing
Figure 13.9 Exception
handling Exception Handling Code
Exceptions may be caused by hardware or software conditions. When an excep-
tion occurs, it must be managed by the system. This can be done within the program
itself or may involve transferring control to a system exception handling mechanism.
Typically, the system’s exception management mechanism reports the error and
shuts down execution. Therefore, to ensure that program exceptions do not cause
system failure, you should define an exception handler for all possible exceptions
that may arise, and make sure that all exceptions are detected and explicitly handled.
In programming languages such as C, if-statements must be used to detect excep-
tions and to transfer control to the exception handling code. This means that you
have to explicitly check for exceptions wherever in the program they may occur.
However, this approach adds significant complexity to the task of exception han-
dling, increasing the chances that you will make mistakes and therefore mishandle
the exception.
Some programming languages, such as Java, C++, and Ada, include constructs that
support exception handling so that you do not need extra conditional statements to
check for exceptions. These programming languages include a special built-in type
(often called Exception) and different exceptions may be declared to be of this type.
When an exceptional situation occurs, the exception is signaled and the language run-
time system transfers control to an exception handler. This is a code section that states
exception names and appropriate actions to handle each exception (Figure 13.9).
Notice that the exception handler is outside the normal flow of control and that this
normal control flow does not resume after the exception has been handled.
Exception handlers usually do one or more of three things:
1. Signal to a higher-level component that an exception has occurred, and provide
information to that component about the type of exception. You use this
approach when one component calls another and the calling component needs to
know if the called component has executed successfully. If not, it is up to the
calling component to take action to recover from the problem.
2. Carry out some alternative processing to that which was originally intended.
Therefore, the exception handler takes some actions to recover from the
problem. Processing may then continue as normal or the exception handler

