micropython

Changeset

769:54289e78af86
2013-12-08 Paul Boddie raw files shortlog changelog graph Moved the exceptions document into the low-level concepts document. syspython-as-target
docs/exceptions.txt docs/lowlevel.txt (file)
     1.1 --- a/docs/exceptions.txt	Sun Dec 08 18:00:53 2013 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,52 +0,0 @@
     1.4 -Exception Handling
     1.5 -==================
     1.6 -
     1.7 -Active Exceptions
     1.8 -=================
     1.9 -
    1.10 -When an exception is raised, an exception instance is defined as the active
    1.11 -exception. This active exception remains in force until either a new exception
    1.12 -is raised in any handling of the exception, or upon exit of a handler where
    1.13 -the active exception has been caught (thus resetting the active exception).
    1.14 -
    1.15 -NOTE: Currently, if classes are used with "raise" statements, no instantiation
    1.16 -NOTE: of such classes occurs. This should be remedied.
    1.17 -
    1.18 -Instructions
    1.19 -------------
    1.20 -
    1.21 -StoreException records the current value reference using the exception
    1.22 -register.
    1.23 -
    1.24 -LoadException obtains the current exception and puts it in the value register.
    1.25 -
    1.26 -CheckException checks the current exception against a class referenced by the
    1.27 -current value.
    1.28 -
    1.29 -ClearException resets the exception register.
    1.30 -
    1.31 -Handlers
    1.32 -========
    1.33 -
    1.34 -An exception handler stack is defined such that when a try...except or
    1.35 -try...finally block is entered, a new handler is defined.
    1.36 -
    1.37 -When an exception is raised, the program jumps to the most recently defined
    1.38 -handler. Inside the handler, the stack entry for the handler will be removed.
    1.39 -
    1.40 -Depending on the nature of the handler and whether the exception is handled,
    1.41 -the program may jump to the next most recent handler, and so on.
    1.42 -
    1.43 -If no handler is defined when an exception is raised or re-raised, the program
    1.44 -should terminate. This might be done by having a "handler #0" which explicitly
    1.45 -terminates the program.
    1.46 -
    1.47 -Instructions
    1.48 -------------
    1.49 -
    1.50 -PushHandler(block) defines an active handler at the location indicated by the
    1.51 -given block.
    1.52 -
    1.53 -PopHandler(n) removes the n topmost active handlers. A single handler is
    1.54 -typically removed when leaving a try block, but potentially more handlers are
    1.55 -removed when such a block is exited using a return statement.
     2.1 --- a/docs/lowlevel.txt	Sun Dec 08 18:00:53 2013 +0100
     2.2 +++ b/docs/lowlevel.txt	Sun Dec 08 18:04:32 2013 +0100
     2.3 @@ -11,6 +11,7 @@
     2.4   * Instantiation
     2.5   * List and tuple representations
     2.6   * Instruction evaluation model
     2.7 + * Exception handling
     2.8  
     2.9  Objects and Structures 
    2.10  ======================
    2.11 @@ -363,3 +364,51 @@
    2.12  Using the approach where arguments are treated like attributes in some kind of
    2.13  structure, we could choose to allocate frames in places other than a stack.
    2.14  This would produce something somewhat similar to a plain tuple object.
    2.15 +
    2.16 +Exception Handling
    2.17 +==================
    2.18 +
    2.19 +Active Exceptions
    2.20 +-----------------
    2.21 +
    2.22 +When an exception is raised, an exception instance is defined as the active
    2.23 +exception. This active exception remains in force until either a new exception
    2.24 +is raised in any handling of the exception, or upon exit of a handler where
    2.25 +the active exception has been caught (thus resetting the active exception).
    2.26 +
    2.27 +The following operations can be employed to achieve this:
    2.28 +
    2.29 +StoreException records the current value reference using the exception
    2.30 +register.
    2.31 +
    2.32 +LoadException obtains the current exception and puts it in the value register.
    2.33 +
    2.34 +CheckException checks the current exception against a class referenced by the
    2.35 +current value.
    2.36 +
    2.37 +ClearException resets the exception register.
    2.38 +
    2.39 +Handlers
    2.40 +--------
    2.41 +
    2.42 +An exception handler stack is defined such that when a try...except or
    2.43 +try...finally block is entered, a new handler is defined.
    2.44 +
    2.45 +When an exception is raised, the program jumps to the most recently defined
    2.46 +handler. Inside the handler, the stack entry for the handler will be removed.
    2.47 +
    2.48 +Depending on the nature of the handler and whether the exception is handled,
    2.49 +the program may jump to the next most recent handler, and so on.
    2.50 +
    2.51 +If no handler is defined when an exception is raised or re-raised, the program
    2.52 +should terminate. This might be done by having a "handler #0" which explicitly
    2.53 +terminates the program.
    2.54 +
    2.55 +The following operations can be employed to achieve this:
    2.56 +
    2.57 +PushHandler(block) defines an active handler at the location indicated by the
    2.58 +given block.
    2.59 +
    2.60 +PopHandler(n) removes the n topmost active handlers. A single handler is
    2.61 +typically removed when leaving a try block, but potentially more handlers are
    2.62 +removed when such a block is exited using a return statement.