with Ada.Exceptions; use Ada.Exceptions;

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure exceptions3 is

    Too_Large, Too_Small: Exception;

    procedure sub1(i: out integer) is 
    begin
        put("Enter a number in range 1 .. 10 : ");
        get(i);

        if i < 1 then
            raise Too_Small with "Value was " & i'img;
        elsif i > 10 then
            raise Too_Large with "Value was " & i'img;
        end if;
        put_line("sub1 is finished");
    end sub1;


   num: Integer;
begin

   sub1(num);
   put_line("Number is " & num'img);
exception

   when e: Too_Large | Too_Small =>
      put(Exception_Name(e) & ".  ");
      put(Exception_Message(e)  & ".  Invalid Number. Bailing out!");

   when e: others =>
      put_line("Exception: " & Exception_Name(e));
      put_line("Exception message: " & Exception_Message(e));
      put_line("Bailing out!");

end exceptions3;

-- SAMPLE RUN 1:
-- Enter a number in range 1 .. 10 : 0
-- EXCEPTIONS3.TOO_SMALL.  Value was  0.  Invalid Number. Bailing out!
-- Value was  0.  Invalid Number. Bailing out!

-- SAMPLE RUN 2:
-- Enter a number in range 1 .. 10 : 11
-- EXCEPTIONS3.TOO_LARGE.  
-- Value was  11.  Invalid Number. Bailing out!

-- SAMPLE RUN 3:
-- Enter a number in range 1 .. 10 : a
-- Exception: ADA.IO_EXCEPTIONS.DATA_ERROR
-- Exception message: a-tiinio.adb:86 instantiated at a-inteio.ads:18
-- Bailing out!