-- Demonstrates exception handling
-- Program terminates when exception occurs
-- Begin-exception-end is similar to a java try-catch
with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
procedure excep1a is
n: Natural;
begin
get(n);
put_line(n'img);
exception
when data_error =>
put_line("You must enter a number!");
when constraint_error =>
put_line("You must enter an non-negative value!");
when end_error =>
put_line("Premature end of file!");
when others =>
put_line("Unknown exception occurred!");
end excep1a;