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

Bryan Olson fakeaddress at nowhere.org
Sun Mar 9 12:57:08 CET 2008

Lie wrote:
> Soft Exception is an exception that if is unhandled, pass silently as
> if nothing happened.

> Implementation:
> Simple implementation might be done by catching all exceptions at the
> highest level, then filtering which exceptions would be stopped (Soft
> Exception) and which exceptions will be reraised and terminate the
> program (Hard Exception). This is simple and can be easily implemented
> but is inefficient as that means all soft exceptions must bubble
> through its way to the top to find out if it is Soft or Hard.

If I'm following what you want, that "simple implementation" does
not work.  If a function, possibly deep in a call stack, raises a
soft exception that no caller above catches, what executes next?

Correct me if I'm misunderstanding your idea: You want raising
an un-caught soft exception to be equivalent to a 'pass';
execution continues as if the 'raise' never happened.

Catching everything at a high level does nothing like that. The
exception causes execution to leave the function invoking the
raise statement, and abolishes the stack state from the point of
the raise to the point of the catch.

As Python exceptions currently work, "catching all exceptions
at the highest level" is either what Python already does, or
ill-defined nonsense. When an exception is uncaught, there is
no useful "highest level", other than the level at which the
program simply fails. Python *must* terminate execution upon
an unhanded exception, because the program defined no state
from which executions could correctly continue.

> 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.

The described problems do not include the "where should execution
resume" problem, which I think is central to the issue. Correct me
if I've misunderstood: A "soft" exception is one that gets raised
only if some calling frame has arranged to catch it.

The if-exception-would-be-unhanded-then-pass logic strikes me as
interesting. It would be a huge change to Python, so I doubt it
will get traction here.  Still, I'd say it's worth more
consideration and discussion.


More information about the Python-list mailing list