What c.l.py's opinions about Soft Exception?

Kay Schluehr kay.schluehr at gmx.net
Sun Mar 9 00:05:50 EST 2008


On 9 Mrz., 04:51, Lie <Lie.1... at gmail.com> wrote:

> A more through implementation would start from the raiser inspecting
> the execution stack and finding whether there are any try block above
> it, if no try block exist it pass silently and if one exist it will
> check whether it have a matching except clause. This also circumvents
> a problem that simple implementation have, as described below.

This will not be easy in particular in the presence of inheritance and
dynamism. There is no way to statically decide whether an exception
BException has the type AException and will be caught by the except
clause in

try:
    BLOCK
except AException, e:
    print "SoftException %s caught"%e

A feasible solution was to invert the try...except statement and
creating a continuation.

catch AException, a:
   print "SoftException A: %s"%a
catch BException , b:
   print "SoftException B: %s"%b
...
in:
   BLOCK

Here each SoftException is raised initially when a catch clause is
entered and a continuation is created that returns to the catch block
of the raised SoftException if required. When a SoftException is
raised within BLOCK a lookup will be made and if a corresponding
SoftException was found that was raised by a catch-clause the current
control flow will be suspended and the continuation is called.



More information about the Python-list mailing list