micropython

docs/exceptions.txt

511:3c26bdc2d8e5
2012-05-29 Paul Boddie Fixed/updated instance attributes definition note.
     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(n) removes the n topmost active handlers. A single handler is
    51 typically removed when leaving a try block, but potentially more handlers are
    52 removed when such a block is exited using a return statement.