-- ada programming problem from -- rick duley -- edith cowan university -- perth, western australia -- [log in to unmask] -- -- explanations, suggestions, solutions please -- with Ada.Text_Io; use Ada.Text_Io; with Ada.Exceptions; use Ada.Exceptions; procedure Fall_Off_The_End is -- -- in the PC implementation for which this program was -- written and compiled with GNAT 3.13p the maximum -- integer value (Integer'Last) is 2,147,486,647 -- this program starts with something close and increments -- until the value is exceeded -- the idea is to show that CONSTRAINT_ERROR is raised and -- can be protected against without intefering with the -- run of the program -- -- oops! -- Start : constant Integer := 2_147_483_600; Log_File : File_Type; begin -- Fall_Off_The_End Create (File => Log_File, Mode => Out_File, Name => "Fall_Off_The_End.txt"); Count_Loop: for Count in 1 .. 100 loop Protect_Block: declare -- this is where the fun should begin Current : Integer := Start + Count; -- once the value of Count exceeds 47 this -- assignment should (IMHO) raise -- CONSTRAINT_ERROR and drive the point of -- control into the exception handler begin -- Protect_Block Put_Line(Item => Integer'Image(Current)); Put_Line(File => Log_File, Item => Integer'Image(Current)); exception when Error: others => -- write to log file Put_Line(File => Log_File, Item => Exception_Name(Error)); Put_Line(File => Log_File, Item => Exception_Message(Error)); Put_Line(File => Log_File, Item => "Resetting Current to" & Integer'Image(Integer'Last)); -- reset operating value Current := Integer'Last; -- confirm in log file Put_Line(File => Log_File, Item => Integer'Image(Current)); -- write to screen Put_Line(Item => Exception_Name(Error)); Put_Line(Item => Exception_Message(Error)); Put_Line(Item => "Current reset to" & Integer'Image(Integer'Last)); Put_Line(Item => Integer'Image(Current)); end Protect_Block; end loop Count_Loop; Ada.Text_Io.Close (File => Log_File); end Fall_Off_The_End;