[Home] [Prev] [Next] [Index]

11.2 Exception Handlers

11.2 Exception Handlers

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

2
exception_handler ::=
when exception_choice {| exception_choice} =>
      sequence_of_statements

exception_choice ::= exception_name | others

3
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:

4
begin
      sequence_of_statements
exception
      exception_handler
     {exception_handler}
end

5
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.

6
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.

7
Example:

begin
     -- sequence of statements
exception
     when SINGULAR | NUMERIC_ERROR =>
          PUT(" MATRIX IS SINGULAR ");
     when others =>
          PUT(" FATAL ERROR ");
     raise ERROR;
end;

Note:

8
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.

9
References:

*
block statement 5.6

*
declarative part 3.9

*
exception 11

*
exception handling 11.4

*
function body 6.3

*
generic body 12.2

*
generic unit 12.1

*
name 4.1

*
package body 7.1

*
raise statement 11.3

*
return statement 5.8

*
sequence of statements 5.1

*
statement 5

*
subprogram body 6.3

*
task body 9.1

*
task unit 9

*
task unit 9.1

*
visibility 8.3



[Home] [Prev] [Next] [Index]

documentation@rational.com
Copyright © 1993-2000, Rational Software Corporation. All rights reserved.