Lady Ada

Ada '83 Language Reference Manual

Copyright 1980, 1982, 1983 owned by the United States Government. Direct reproduction and usage requests to the Ada Information Clearinghouse.

11.2. Exception Handlers


The response to one or more exceptions is specified by an exception handler.

    exception_handler ::=
       when exception_choice {| exception_choice} =>
    exception_choice ::= exception_name | others 

An exception handler occurs in a construct that is either a block statement or the body of a subprogram, package, task unit, or generic unit. Such a construct will be called a frame in this chapter. In each case the syntax of a frame that has exception handlers includes the following part:


The exceptions denoted by the exception names given as exception choices of a frame must all be distinct. The exception choice others is only allowed for the last exception handler of a frame and as its only exception choice; it stands for all exceptions not listed in previous handlers of the frame, including exceptions whose names are not visible at the place of the exception handler.

The exception handlers of a frame handle exceptions that are raised by the execution of the sequence of statements of the frame. The exceptions handled by a given exception handler are those named by the corresponding exception choices.


       --  sequence of statements
          PUT(" MATRIX IS SINGULAR ");
       when others =>
          PUT(" FATAL ERROR ");
          raise ERROR;


The same kinds of statement are allowed in the sequence of statements of each exception handler as are allowed in the sequence of statements of the frame. For example, a return statement is allowed in a handler within a function body.

References: block statement, declarative part, exception, exception handling, function body, generic body, generic unit, name, package body, raise statement, return statement, sequence of statements, statement, subprogram body, task body, task unit, and 9.1, visibility.

Rationale references: 14.2.2 Exception Handlers, 14.2.4 Association of Handlers with Exceptions, 14.2.7 Order of Exceptions

Style Guide references: 2.1.2 Indentation, 4.3.1 Using Exceptions to Help Define an Abstraction, 5.6.9 Blocks, 5.8.1 Handling Versus Avoiding Exceptions, 5.8.2 Handlers for others, 5.8.3 Propagation, 5.8.4 Localizing the Cause of an Exception, 6.2.2 Defensive Task Communication, 6.3.1 Avoiding Termination, 6.3.4 Abnormal Termination, 7.5.2 Constraint_Error and Numeric_Error, 7.5.3 Implementation-Defined Exceptions, 8.2.7 Exceptions


[Ada Information Clearinghouse]

Address any questions or comments to