Concepts of Programming Languages

(Sean Pound) #1

636 Chapter 14 Exception Handling and Event Handling


somewhat philosophical, particularly in the case of predefined error conditions.
For example, suppose a language has a predefined exception that is raised when
a subscript range error occurs. Many believe that subscript range errors should
always be detected, and therefore it should not be possible for the program to
disable detection of these errors. Others argue that subscript range checking is
too costly for production software, where, presumably, the code is sufficiently
error free that range errors should not occur.
The exception-handling design issues can be summarized as follows:


  • How and where are exception handlers specified, and what is their scope?

  • How is an exception occurrence bound to an exception handler?

  • Can information about an exception be passed to the handler?

  • Where does execution continue, if at all, after an exception handler com-
    pletes its execution? (This is the question of continuation or resumption.)

  • Is some form of finalization provided?

  • How are user-defined exceptions specified?

  • If there are predefined exceptions, should there be default exception han-
    dlers for programs that do not provide their own?

  • Can predefined exceptions be explicitly raised?

  • Are hardware-detectable errors treated as exceptions that may be handled?

  • Are there any predefined exceptions?

  • Should it be possible to disable predefined exceptions?
    We are now in a position to examine the exception-handling facilities of
    three contemporary programming languages.


14.2 Exception Handling in Ada


Exception handling in Ada is a powerful tool for constructing more reliable
software systems. It is based on the good parts of the exception-handling design
of two earlier languages with exception handling—PL/I and CLU.

14.2.1 Exception Handlers


Ada exception handlers are often local to the code in which the exception can
be raised (although they can be propagated to other program units). Because
this provides them with the same referencing environment, parameters for
handlers are not necessary and are not allowed. Therefore, if an exception is
handled in a unit different from the unit that raised the exception, no informa-
tion about the exception can be passed to the handler.^3


  1. Not quite true. It is possible for the handler to retrieve the exception name, a short descrip-
    tion of the exception, and the approximate location where the exception was raised.

Free download pdf