type Exception_Id is private;
Null_Id : constant Exception_Id;
function Exception_Name(Id : Exception_Id) return String;
type Exception_Occurrence_Access is access all Exception_Occurrence;
Null_Occurrence : constant Exception_Occurrence;
function Exception_Message(X : Exception_Occurrence) return String;
procedure Reraise_Occurrence(X : in Exception_Occurrence);
function Exception_Name(X : Exception_Occurrence) return String;
--Same as Exception_Name(Exception_Identity(X)).
function Exception_Information(X : Exception_Occurrence) return String;
Source : in Exception_Occurrence);
function Save_Occurrence(Source : Exception_Occurrence)
return Exception_Occurrence_Access;
private
... --not specified by the language
end Ada.Exceptions;
Cleanup;
raise;
limited record
Id : Exception_Id;
Message : String(1..Message_Length);
end record;
limited record
case Kind is
when Normal =>
... --space for 200 characters
when As_Choice_Param =>
... --pointer to heap string
end case;
end record;
begin
Raise_Exception(Identity(X), Exception_Message(X));
end Reraise_Occurrence;
use Ada;
package File_System is
type File_Handle is limited private;
procedure Open(F : in out File_Handle; Name : String);
--raises File_Not_Found if named file does not exist
procedure Read(F : in out File_Handle; Data : out Data_Type);
--raises End_Of_File if the file is not open
procedure Open(F : in out File_Handle; Name : String) is
begin
if File_Exists(Name) then
...
else
Exceptions.Raise_Exception(File_Not_Found'Identity,
"File not found: " & Name & ".");
end if;
end Open;
begin
if F.Current_Position <= F.Last_Position then
...
else
raise End_Of_File;
end if;
end Read;
with Ada.Exceptions;
with File_System; use File_System;
use Ada;
procedure Main is
begin
... --call operations in File_System
exception
when End_Of_File =>
Close(Some_File);
when Not_Found_Error : File_Not_Found =>
Text_IO.Put_Line(Exceptions.Exception_Message(Not_Found_Error));
when The_Error : others =>
Text_IO.Put_Line("Unknown error:");
if Verbosity_Desired then
Text_IO.Put_Line(Exceptions.Exception_Information(The_Error));
else
Text_IO.Put_Line(Exceptions.Exception_Name(The_Error));
Text_IO.Put_Line(Exceptions.Exception_Message(The_Error));
end if;
raise;
end Main;