micropython

Annotated docs/exceptions.txt

232:2ede6db71ceb
2009-05-31 Paul Boddie Fixed the structure of "if" statement code. Fixed comparison method definitions for equality and inequality. Added optimisation where exception handlers are pushed and popped without any code defined between these operations. Reviewed exception handling including that employed around operators, introducing PopHandler and ClearException instructions in order to properly maintain exception state. Added RSVP support for some integer comparisons. Split the compare2 test program into separate tests. Added some exception-related documentation.
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@232 12
Handlers
paul@232 13
========
paul@57 14
paul@109 15
An exception handler stack is defined such that when a try...except or
paul@109 16
try...finally block is entered, a new handler is defined.
paul@57 17
paul@109 18
When an exception is raised, the program jumps to the most recently defined
paul@109 19
handler. Inside the handler, the stack entry for the handler will be removed.
paul@57 20
paul@109 21
Depending on the nature of the handler and whether the exception is handled,
paul@109 22
the program may jump to the next most recent handler, and so on.
paul@57 23
paul@109 24
If no handler is defined when an exception is raised or re-raised, the program
paul@109 25
should terminate. This might be done by having a "handler #0" which explicitly
paul@109 26
terminates the program.
paul@232 27
paul@232 28
Instructions
paul@232 29
------------
paul@232 30
paul@232 31
PushHandler(block) defines an active handler at the location indicated by the
paul@232 32
given block.
paul@232 33
paul@232 34
PopHandler removes the active handler at or after the location indicated by
paul@232 35
the previously given block.