11.4.1 The Package Exceptions

From OC Systems Wiki!
< Guide:95lrm
Revision as of 23:35, 4 May 2019 by imported>WikiVisor (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Static Semantics

The following language-defined library package exists:

package Ada.Exceptions is
    type Exception_Id is private;
    Null_Id : constant Exception_Id; 
    function Exception_Name(Id Exception_Id) return String;

    type Exception_Occurrence is limited private; 
    type Exception_Occurrence_Access is access all Exception_Occurrence; 
    Null_Occurrence : constant Exception_Occurrence;

    procedure Raise_Exception(E in Exception_Id; 
                           Message in String := ""); 
    function Exception_Message(X Exception_Occurrence) return String; 
    procedure Reraise_Occurrence(X in Exception_Occurrence);

    function Exception_Identity(X Exception_Occurrence) 
                             return Exception_Id; 
    function Exception_Name(X Exception_Occurrence) return String; 
       -- Same as Exception_Name(Exception_Identity(X)). 
    function Exception_Information(X Exception_Occurrence) return String;

    procedure Save_Occurrence(Target out Exception_Occurrence; 
                           Source in Exception_Occurrence); 
    function Save_Occurrence(Source Exception_Occurrence) 
                           return Exception_Occurrence_Access;
    ... -- not specified by the language
end Ada.Exceptions;

Each distinct exception is represented by a distinct value of type Exception_Id. Null_Id does not represent any exception, and is the default initial value of type Exception_Id. Each occurrence of an exception is represented by a value of type Exception_Occurrence. Null_Occurrence does not represent any exception occurrence, and is the default initial value of type Exception_Occurrence.

For a prefix E that denotes an exception, the following attribute is defined:

E'Identity returns the unique identity of the exception. The type of this attribute is Exception_Id.

Raise_Exception raises a new occurrence of the identified exception. In this case, Exception_Message returns the Message parameter of Raise_Exception. For a raise_statement with an exception_name, Exception_Message returns implementation-defined information about the exception occurrence. Reraise_Occurrence reraises the specified exception occurrence.

Exception_Identity returns the identity of the exception of the occurrence.

The Exception_Name functions return the full expanded name of the exception, in upper case, starting with a root library unit. For an exception declared immediately within package Standard, the defining_identifier is returned. The result is implementation defined if the exception is declared within an unnamed block_statement.

Exception_Information returns implementation-defined information about the exception occurrence.

Raise_Exception and Reraise_Occurrence have no effect in the case of Null_Id or Null_Occurrence. Exception_Message, Exception_Identity, Exception_Name, and Exception_Information raise Constraint_Error for a Null_Id or Null_Occurrence.

The Save_Occurrence procedure copies the Source to the Target. The Save_Occurrence function uses an allocator of type Exception_Occurrence_Access to create a new object, copies the Source to this new object, and returns an access value designating this new object; the result may be deallocated using an instance of Unchecked_Deallocation.

Implementation Requirements

The implementation of the Write attribute (see 13.13.2) of Exception_Occurrence shall support writing a representation of an exception occurrence to a stream; the implementation of the Read attribute of Exception_Occurrence shall support reconstructing an exception occurrence from a stream (including one written in a different partition).

Implementation Permissions

An implementation of Exception_Name in a space-constrained environment may return the defining_identifier instead of the full expanded name.

The string returned by Exception_Message may be truncated (to no less than 200 characters) by the Save_Occurrence procedure (not the function), the Reraise_Occurrence procedure, and the re-raise statement.

Implementation Advice

Exception_Message (by default) and Exception_Information should produce information useful for debugging. Exception_Message should be short (about one line), whereas Exception_Information can be long. Exception_Message should not include the Exception_Name. Exception_Information should include both the Exception_Name and the Exception_Message.

Copyright © 1992,1993,1994,1995 Intermetrics, Inc.
Copyright © 2000 The MITRE Corporation, Inc. Ada Reference Manual