This appendix summarizes the predefined Ada exceptions. Ada distinguishes exceptions defined in the language from those defined in standard packages. The summary should help students to write exception handlers and to interpret run-time messages that report unhandled exceptions propagated out of a main program.
Constraint_Error
is raised if an attempt is made to store a
value in a variable that is out of range for that variable, that is, out of the
range of the variable's type or subtype. It will also be raised if an attempt
is made to dereference a null access value (pointer), or to copy a string or
similar array into another of a different size, or to copy a variant record
object into another which is constrained to a different value of the
discriminant.
Program_Error
is raised in a number of situations unlikely to
arise in courses that use this book. For example, WITH
-ing a
number of packages may cause an attempted call of a subprogram whose body has
not yet been elaborated. This occurrence is rare in student projects with
simple package dependencies, but arises occasionally in industry.
Storage_Error
is raised if the storage pool is exhausted by
dynamic allocation, typically in an infinite loop in whose body a
NEW
call is executed. The exception is also raised if the run-time
stack is exhausted by subprogram calls, for example, by an infinite recursion.
Tasking_Error
is raised if two concurrent Ada tasks are
unable to communicate. This exception should never be raised in programs based
on material in this book, which does not use tasking at all.
Ada.Calendar
:
Ada.Calendar.Time_Error
is raised if the actual parameters in
a call of Ada.Calendar.Time_Of
do not form a valid date, or if
subtracting two values of type Ada.Calendar.Time
results in a
value that lies outside the range of the predefined type
Duration
.Ada.Numerics
:
Argument_Error
exception is raised by a subprogram in a
child unit of Ada.Numerics
to signal that one or more of the
actual subprogram parameters are outside the domain of the corresponding
mathematical function.Ada.Text_IO
operations:
Ada.Text_IO.Status_Error
is raised by an attempt to operate
upon a file that is not open, and by an attempt to open a file that is already
open.
Ada.Text_IO.Mode_Error
is raised by an attempt to read from,
or test for the end of, a file whose current mode is Out_File
, and
also by an attempt to write to a file whose current mode is
In_File
. This exception is also raised by specifying a file whose
current mode is Out_File
in a call of Set_Input
,
Skip_Line
, End_Of_Line
, Skip_Page
, or
End_Of_Page
; or by specifying a file whose current mode is
In_File
in a call of Set_Output
,
Set_Line_Length
, Set_Page_Length
,
Line_Length
, Page_Length
, New_Line
, or
New_Page
.
Ada.Text_IO.Name_Error
is raised by a call of
Create
or Open
if the string given for the parameter
Name
does not allow the identification of an external file. For
example, this exception is raised if the string is improper, or, alternatively,
if either none or more than one external file corresponds to the string. In
student programs, this exception is often raised if the case of the file
name given in the procedure call does not agree with the case of the name in
the student's directory. This is especially common in Unix, in which file names
are case-sensitive.
Ada.Text_IO.Use_Error
is raised if an operation is attempted
that is not possible for reasons that depend on characteristics of the external
file. For example, this exception in raised by the procedure
Create
, among other circumstances, if the given mode is
Out_File
but the form specifies an input only device, if the
parameter Form
specifies invalid access rights, or if an external
file with the given name already exists and overwriting is not allowed.
Ada.Text_IO.Device_Error
is raised if an input-output
operation cannot be completed because of a malfunction of the underlying
system. This should rarely occur in a student program.
Ada.Text_IO.End_Error
is raised by an attempt to skip (read
past) the end of a file. In student programs, this may happen if the file
terminator is immediately preceded by a line terminator. In this case a
solution is to include a handler for this exception in the file input section
of the program. Sometimes inserting a Ada.Text_IO.Skip_Line
call
in the file input loop will work as well.
Ada.Text_IO.Data_Error
is raised by a procedure
Get
if the input character sequence fails to satisfy the required
syntax, or if the value input does not belong to the range of the required type
or subtype. Common causes are entering an integer or character literal where a
Float
literal is required, or entering an invalid enumeration
literal.
Ada.Text_IO.Layout_Error
is raised by Col
,
Line
, or Page
if the value returned exceeds
Count'Last
. The exception Layout_Error
is also raised
on output by an attempt to set column or line numbers in excess of specified
maximum line or page lengths, respectively (excluding the unbounded cases). It
is also raised by an attempt to Put
too many characters to a
string.
Copyright © 1996 by Addison-Wesley Publishing Company, Inc.