11.2 Exception Handlers
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[The response to one or more exceptions is specified by an
name | others
A choice with an exception_
name covers the named exception. A choice with others covers all exceptions not named by previous choices of the same
handled_sequence_of_statements. Two choices in different
exception_handlers of the same
handled_sequence_of_statements shall not cover the same exception.
An others choice even covers exceptions that are not visible at the place of the handler. Since exception raising is a dynamic activity, it is entirely possible for an others handler to handle an exception that it could not have named.
A choice with others is allowed only for the last handler of a
handled_sequence_of_statements and as the only choice of that handler.
name of a choice shall not denote an exception declared in a generic formal package.
This is because the compiler doesn't know the identity of such an exception, and thus can't enforce the coverage rules.
choice_parameter_specification declares a choice parameter, which is a constant object of type Exception_Occurrence (see 11.4.1). During the handling of an exception occurrence, the choice parameter, if any, of the handler represents the exception occurrence that is being handled.
The execution of a
handled_sequence_of_statements consists of the execution of the
sequence_of_statements. [The optional handlers are used to handle any exceptions that are propagated by the
Example of an exception handler:
Extensions to Ada 83
exception_choices of the same
exception_handler may cover the same exception. This allows for “when Numeric_Error | Constraint_Error =>” even though Numeric_Error is a rename of Constraint_Error. This also allows one to “with” two different I/O packages, and then write, for example, “when Ada.Text_IO.Data_Error | My_Seq_IO.Data_Error =>” even though these might both be renames of the same exception.