* here are all of the Exception examples bundled into one place * you need to separate them to play with them. with ada.integer_text_io; with ada.text_io; procedure testExceptions0 is subtype tinyNumber is integer range 1..5; number : tinyNumber; begin ada.text_io.put (" please enter an integer in the range 1 to 5 "); ada.integer_text_io.get (number); ada.text_io.new_line; ada.text_io.put (" you entered: "); ada.integer_text_io.put (number); end testExceptions0; ************************** with ada.integer_text_io; with ada.text_io; procedure testExceptions1 is subtype tinyNumber is integer range 1..5; number : tinyNumber; begin ada.text_io.put (" please enter an integer in the range 1 to 5 "); ada.integer_text_io.get (number); ada.text_io.new_line; ada.text_io.put (" you entered: "); ada.integer_text_io.put (number); exception when constraint_error => ada.text_io.put (" the value you entered was not in the range 1 to 5 "); end testExceptions1; ************************** with ada.io_exceptions; -- required for data_error with ada.integer_text_io; with ada.text_io; procedure testExceptions2 is subtype tinyNumber is integer range 1..5; number : tinyNumber; begin ada.text_io.put (" please enter an integer in the range 1 to 5 "); ada.integer_text_io.get (number); ada.text_io.new_line; ada.text_io.put (" you entered: "); ada.integer_text_io.put (number); exception when constraint_error => ada.text_io.put (" the value you entered was not an integer in the range 1 to 5 "); when ada.io_exceptions.Data_error => ada.text_io.put (" the value you entered was not an integer "); end testExceptions2; ************************** with ada.io_exceptions; -- required for data_error with ada.integer_text_io; with ada.text_io; procedure testExceptions3 is subtype tinyNumber is integer range 1..5; number : tinyNumber; dinky : exception; -- declaration of a user-defined exception begin ada.text_io.put (" please enter an integer in the range 1 to 5 "); ada.integer_text_io.get (number); ada.text_io.new_line; ada.text_io.put (" you entered: "); ada.integer_text_io.put (number); ada.text_io.new_line; if (number = 3) then raise dinky; -- this will raises the user-defined exception end if; exception when constraint_error => ada.text_io.put (" the value you entered was not an integer in the range 1 to 5 "); when ada.io_exceptions.Data_error => ada.text_io.put (" the value you entered was not an integer "); when dinky => -- handles the user-defined exception ada.text_io.put (" the value you entered was 3 "); end testExceptions3; **************************