An exception declaration declares a name for an exception. The name of an exception can only be used in raise statements, exception handlers, and renaming declarations.
exception_declaration ::= identifier_list : exception;
An exception declaration with several identifiers is equivalent to a sequence of single exception declarations, as explained in section 3.2. Each single exception declaration declares a name for a different exception. In particular, if a generic unit includes an exception declaration, the exception declarations implicitly generated by different instantiations of the generic unit refer to distinct exceptions (but all have the same identifier). The particular exception denoted by an exception name is determined at compilation time and is the same regardless of how many times the exception declaration is elaborated. Hence, if an exception declaration occurs in a recursive subprogram, the exception name denotes the same exception for all invocations of the recursive subprogram.
The following exceptions are predefined in the language; they are raised when the situations described are detected.
CONSTRAINT_ERROR This exception is raised in any of the following situations: upon an attempt to violate a range constraint, an index constraint, or a discriminant constraint; upon an attempt to use a record component that does not exist for the current discriminant values; and upon an attempt to use a selected component, an indexed component, a slice, or an attribute, of an object designated by an access value, if the object does not exist because the access value is null. NUMERIC_ERROR This exception is raised by the execution of a predefined numeric operation that cannot deliver a correct result (within the declared accuracy for real types); this includes the case where an implementation uses a predefined numeric operation for the execution, evaluation, or elaboration of some construct. The rules given in section 4.5.7 define the cases in which an implementation is not required to raise this exception when such an error situation arises; see also section 11.6. PROGRAM_ERROR This exception is raised upon an attempt to call a subprogram, to activate a task, or to elaborate a generic instantiation, if the body of the corresponding unit has not yet been elaborated. This exception is also raised if the end of a function is reached (see 6.5); or during the execution of a selective wait that has no else part, if this execution determines that all alternatives are closed (see 9.7.1). Finally, depending on the implementation, this exception may be raised upon an attempt to execute an action that is erroneous, and for incorrect order dependences (see 1.6). STORAGE_ERROR This exception is raised in any of the following situations: when the dynamic storage allocated to a task is exceeded; during the evaluation of an allocator, if the space available for the collection of allocated objects is exhausted; or during the elaboration of a declarative item, or during the execution of a subprogram call, if storage is not sufficient. TASKING_ERROR This exception is raised when exceptions arise during intertask communication (see 9 and 11.5).
The situations described above can arise without raising the corresponding exceptions, if the pragma SUPPRESS has been used to give permission to omit the corresponding checks (see 11.7).
Examples of user-defined exception declarations:
SINGULAR : exception; ERROR : exception; OVERFLOW, UNDERFLOW : exception;
References: access value, collection, declaration, exception, exception handler, generic body, generic instantiation, generic unit, identifier, implicit declaration, instantiation, name, object, raise statement, real type, record component, return statement, subprogram, subprogram body, task, task body.
Constraint_error exception contexts: aggregate 4.3.1 4.3.2, allocator 4.8, assignment statement 5.2 5.2.1, constraint 3.3.2, discrete type attribute 3.5.5, discriminant constraint 3.7.2, elaboration of a generic formal parameter 12.3.1 12.3.2 12.3.4 12.3.5, entry index 9.5, exponentiating operator 4.5.6, index constraint 3.6.1, indexed component 4.1.1, logical operator 4.5.1, null access value 3.8, object declaration 3.2.1, parameter association 6.4.1, qualified expression 4.7, range constraint 3.5, selected component 4.1.3, slice 4.1.2, subtype indication 3.3.2, type conversion 4.6
Numeric_error exception contexts: discrete type attribute 3.5.5, implicit conversion 3.5.4 3.5.6 4.6, numeric operation 3.5.5 3.5.8 3.5.10, operator of a numeric type 4.5 4.5.7
Program_error exception contexts: collection 3.8, elaboration 3.9, elaboration check 3.9 7.3 9.3 12.2, erroneous 1.6, incorrect order dependence 1.6, leaving a function 6.5, selective wait 9.7.1
Storage_error exception contexts: allocator 4.8
Tasking error exception contexts: abort statement 9.10, entry call 9.5 9.7.2 9.7.3, exceptions during task communication 11.5, task activation 9.3
Rationale references: 14.2.1 Declaration of Exceptions
Style Guide references: 3.3.5 Data Comments, 4.3.1 Using Exceptions to Help Define an Abstraction, 5.4.3 Dynamic Data, 7.5.2 Constraint_Error and Numeric_Error, 7.5.3 Implementation-Defined Exceptions
Address any questions or comments to firstname.lastname@example.org.