micropython

Annotated docs/exceptions.txt

470:138fa7678c43
2011-09-12 Paul Boddie Filtered out unused classes from the descendants stored for each class in the object table. Especially for the 'object' class, this makes it possible to reduce the table substantially.
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@241 12
NOTE: Currently, if classes are used with "raise" statements, no instantiation
paul@241 13
NOTE: of such classes occurs. This should be remedied.
paul@241 14
paul@233 15
Instructions
paul@233 16
------------
paul@233 17
paul@233 18
StoreException records the current value reference using the exception
paul@233 19
register.
paul@233 20
paul@233 21
LoadException obtains the current exception and puts it in the value register.
paul@233 22
paul@233 23
CheckException checks the current exception against a class referenced by the
paul@233 24
current value.
paul@233 25
paul@233 26
ClearException resets the exception register.
paul@233 27
paul@232 28
Handlers
paul@232 29
========
paul@57 30
paul@109 31
An exception handler stack is defined such that when a try...except or
paul@109 32
try...finally block is entered, a new handler is defined.
paul@57 33
paul@109 34
When an exception is raised, the program jumps to the most recently defined
paul@109 35
handler. Inside the handler, the stack entry for the handler will be removed.
paul@57 36
paul@109 37
Depending on the nature of the handler and whether the exception is handled,
paul@109 38
the program may jump to the next most recent handler, and so on.
paul@57 39
paul@109 40
If no handler is defined when an exception is raised or re-raised, the program
paul@109 41
should terminate. This might be done by having a "handler #0" which explicitly
paul@109 42
terminates the program.
paul@232 43
paul@232 44
Instructions
paul@232 45
------------
paul@232 46
paul@232 47
PushHandler(block) defines an active handler at the location indicated by the
paul@232 48
given block.
paul@232 49
paul@398 50
PopHandler(n) removes the n topmost active handlers. A single handler is
paul@398 51
typically removed when leaving a try block, but potentially more handlers are
paul@398 52
removed when such a block is exited using a return statement.