11.3 Raise Statements
Syntax
Legality Rules
The
name,
if any, in a
raise_statement
shall denote an exception.
{re-raise
statement} A
raise_statement
with no
exception_name
(that is, a
re-raise statement) shall be within a handler, but
not within a body enclosed by that handler.
Name Resolution Rules
Dynamic Semantics
{
AI95-00361-01}
{raise (an exception)} To
raise an exception is to raise a new occurrence of that exception[,
as explained in
11.4].
{execution
(raise_statement with an exception_name) [partial]} For
the execution of a
raise_statement
with an
exception_name,
the named exception is raised. [If a
string_expression
is present, the
expression
is evaluated and its value is associated with the exception occurrence.]
{execution (re-raise statement) [partial]}
For the execution of a re-raise statement, the exception
occurrence that caused transfer of control to the innermost enclosing
handler is raised [again].
Proof: {
AI95-00361-01}
The definition of Exceptions.Exception_Message includes a statement that
the string is returned (see
11.4.1). We
describe the use of the string here so that we don't have an unexplained
parameter in this subclause.
Implementation Note: For a re-raise statement,
the implementation does not create a new Exception_Occurrence, but instead
propagates the same Exception_Occurrence value. This allows the original
cause of the exception to be determined.
Examples
Examples of raise
statements:
{
AI95-00433-01}
raise Ada.IO_Exceptions.Name_Error; --
see A.13
raise Queue_Error
with "Buffer Full"; --
see 9.11
raise; -- re-raise the current exception
Wording Changes from Ada 83
The fact that the
name
in a
raise_statement
has to denote an exception is not clear from RM83. Clearly that was the
intent, since the italicized part of the syntax rules so indicate, but
there was no explicit rule. RM83-1.5(11) doesn't seem to give the italicized
parts of the syntax any force.
Extensions to Ada 95
{
AI95-00361-01}
{
extensions to Ada 95}
The syntax of a
raise_statement
is extended to include a string message. This is more convenient than
calling Exceptions.Exception_Message (
exception_name'Identity,
string_expression),
and should encourage the use of message strings when raising exceptions.