-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
with Ada.Text_IO,Ada.Integer_Text_IO,Ada.Exceptions;

use Ada.Text_IO,Ada.Integer_Text_IO,Ada.Exceptions;

-- exceptions

procedure Exceptions is

procedure E_1 is

Val : Integer range 1..10;

begin
    Val := 7;
    Val := Val + 7;
    Put(Val,Width=>1);
    New_Line;
    exception
        when Constraint_Error => Put_Line("Out of range");
        when others => Put_Line("Something else");
end E_1;

procedure E_2 is

TestException : exception;

begin
    raise TestException;
    exception
        when Constraint_Error => Put_Line("Out of range");
        when Error : others => Put_Line(Exception_Name(Error));
end;

procedure E_3 is

TestException : exception;

begin
    Raise_Exception(TestException'Identity, "Just a test");
    exception
        when Constraint_Error => Put_Line("Out of range");
        when Error : others => Put_Line(Exception_Message(Error));
end;

begin
    E_1;
    E_2;
    E_3;
end Exceptions; 
