how does exception mechanism work?

bobueland at yahoo.com bobueland at yahoo.com
Mon Dec 12 04:28:30 EST 2005


Sometimes the best way to understand something is to understand the
mechanism behind it. Maybe that is true for exceptions. This is a model
I have right now (which probably is wrong)

1. When a runtime error occurs, some function (probably some class
method) in Python is called behind the scenes.
2. That function goes into a global table having error types in one
column and corresponding flags in another (and probably other columns
used for trace back information). It sets the flag for the error type
that occured.
3. Then the function looks if the error occured inside a try statement
(in the current function or the function that called the current
function, or the one that called that function and so on). If it did
occur inside a try statement it looks if the corresponding exception
handles the occured error type and if so it executes the statements
under the exception clause. The function also resets the type error
flag.
4. If no try statement is found in 3. (or no exception handling the
occured type error) then it is an unhandled error and the Python stops
the execution, prints an error message and resets the global type error
flag)

Is this model correct or wrong? Where can I read about the mechanism
behind exceptions?

Bob




More information about the Python-list mailing list