Whirlwind Tour of Ada - Part 3c

Exception Handling

Begin/End Blocks

Exception Flow of Control

Declaring and Raising Exceptions

Raise Expressions

Exception Parameters and Getting Exception Names



Introduction



Common Built-in Exceptions



Handling Exceptions



When Others



Exceptions and Flow of Control



Example: Exception Flow of Control

  1. Imagine an exception E on the get statement in NO_handler
    1. Exception E is passed to get_two_nats:
      1. If E is an END_ERROR, a message is produced, i and j are set to 0, control is returned to main, and the values of i and j are printed
      2. If E is NOT END_ERROR, then E is passed to main:
        1. If E is CONSTRAINT_ERROR, then a message is printed and the program halts.
        2. If E is NOT CONSTRAINT_ERROR, the the program crashes

  2. Now, imagine an exception E on the get statement in has_handler
    1. Exception E is passed to the handler in has_handler:
      1. If E is DATA_ERROR, a message is produced, i and j are set to 1, control is returned to get_two_nats and then to main, and the values of i and j are printed
      2. If E is NOT DATA_ERROR, then exception E is passed to the exception handler in get_two_nats:
        1. Execution then continues as in case 1.1 above


Begin/End Blocks



Exception Flow of Control and Begin/End Blocks



Exception Control Flow



Declaring and Raising Exceptions



Raise Expressions



Finding and Using an Exception's Name




Another Example