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

Diez B. Roggisch deets at nospam.web.de
Sun Mar 9 17:51:04 EDT 2008


> Perhaps similar technique the compiler uses to determine whether a
> function is a normal function or a generator function? Positive
> forward lookup for any soft exceptions, which would then activate
> matching soft exceptions inside the code?

The difference between generators and functions is made on the 
yield-keyword.

However, the exception-mechanism isn't governed by the compiler, but at 
runtime. You can do things like this:


eclass = HardException if full_moon() else: SoftException

raise eclass()

Which means that you don't stand a chance determining 
soft-exception-usage at compiletime.

What would work is most probably to register soft-exception-handlers 
when encountering them at runtime, thus making raising-code aware of 
them and execute it only if there are one (or several) present.

However, IMHO it's not a worthy extension to the language - for the same 
reasons Steven gave. It seems only useful for tightly coupled code, not 
as a general mechanism. And callbacks or maybe even thread-local state 
are sufficient to deal with that I'd say.


Diez



More information about the Python-list mailing list