micropython

docs/exceptions.txt

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