paul@57 | 1 | Exception Handling
|
paul@232 | 2 | ==================
|
paul@232 | 3 |
|
paul@232 | 4 | Active Exceptions
|
paul@232 | 5 | =================
|
paul@232 | 6 |
|
paul@232 | 7 | When an exception is raised, an exception instance is defined as the active
|
paul@232 | 8 | exception. This active exception remains in force until either a new exception
|
paul@232 | 9 | is raised in any handling of the exception, or upon exit of a handler where
|
paul@232 | 10 | the active exception has been caught (thus resetting the active exception).
|
paul@232 | 11 |
|
paul@233 | 12 | Instructions
|
paul@233 | 13 | ------------
|
paul@233 | 14 |
|
paul@233 | 15 | StoreException records the current value reference using the exception
|
paul@233 | 16 | register.
|
paul@233 | 17 |
|
paul@233 | 18 | LoadException obtains the current exception and puts it in the value register.
|
paul@233 | 19 |
|
paul@233 | 20 | CheckException checks the current exception against a class referenced by the
|
paul@233 | 21 | current value.
|
paul@233 | 22 |
|
paul@233 | 23 | ClearException resets the exception register.
|
paul@233 | 24 |
|
paul@232 | 25 | Handlers
|
paul@232 | 26 | ========
|
paul@57 | 27 |
|
paul@109 | 28 | An exception handler stack is defined such that when a try...except or
|
paul@109 | 29 | try...finally block is entered, a new handler is defined.
|
paul@57 | 30 |
|
paul@109 | 31 | When an exception is raised, the program jumps to the most recently defined
|
paul@109 | 32 | handler. Inside the handler, the stack entry for the handler will be removed.
|
paul@57 | 33 |
|
paul@109 | 34 | Depending on the nature of the handler and whether the exception is handled,
|
paul@109 | 35 | the program may jump to the next most recent handler, and so on.
|
paul@57 | 36 |
|
paul@109 | 37 | If no handler is defined when an exception is raised or re-raised, the program
|
paul@109 | 38 | should terminate. This might be done by having a "handler #0" which explicitly
|
paul@109 | 39 | terminates the program.
|
paul@232 | 40 |
|
paul@232 | 41 | Instructions
|
paul@232 | 42 | ------------
|
paul@232 | 43 |
|
paul@232 | 44 | PushHandler(block) defines an active handler at the location indicated by the
|
paul@232 | 45 | given block.
|
paul@232 | 46 |
|
paul@232 | 47 | PopHandler removes the active handler at or after the location indicated by
|
paul@232 | 48 | the previously given block.
|