home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 17 - Program 5
- package Stuff is
- Funny_Add_Error : exception;
- procedure Add_One(Number : in out INTEGER);
- function Subtract_One(Number : INTEGER) return INTEGER;
- end Stuff;
-
-
-
- with Text_IO;
- use Text_IO;
-
- package body Stuff is
-
- procedure Add_One(Number : in out INTEGER) is
- begin
- Number := Number + 1;
- exception
- when Funny_Add_Error => Put_Line("Funny add error raised");
- when Numeric_Error => Put_Line("Numeric error raised");
- end Add_One;
-
- function Subtract_One(Number : INTEGER) return INTEGER is
- Funny_Subtract_Error : exception;
- begin
- raise Funny_Subtract_Error;
- return Number - 1;
- exception
- when Funny_Add_Error =>
- Put_Line("Funny add error raised");
- raise;
- when Funny_Subtract_Error =>
- Put_Line("Funny subtract error raised");
- raise;
- end Subtract_One;
-
- begin
- null;
- exception
- when Numeric_Error =>
- Put_Line("Numeric error during elaboration");
- when Constraint_Error =>
- Put_Line("Constraint_Error during elaboration");
- when Funny_Add_Error =>
- Put_Line("Funny Add error during elaboration");
- -- when Funny_Subtract_Error =>
- -- Put_Line("Funny subtract error during elaboration");
- end Stuff;
-
-
-
- with Text_IO, Stuff;
- use Text_IO, Stuff;
-
- procedure Except5 is
- Index : INTEGER := 5;
- Add_Error : exception renames Stuff.Funny_Add_Error;
- begin
- Add_One(Index);
- Index := Subtract_One(Index);
- exception
- when Numeric_Error | Constraint_Error =>
- Put_Line("Numeric error or constraint error raised.");
- when Add_Error =>
- Put_Line("Addition error detected");
- when others =>
- Put_Line("An unknown exception raised");
- raise; -- Raise it again for the operating system
- end Except5;
-
-
-
-
- -- Result of execution
-
- -- Funny subtract error raised
- -- An unknown exception raised
- -- Unhandled exception; funny_subtract_error
-
-