[pypy-dev] [gmane.comp.python.pypy] deep breakage

Armin Rigo arigo at tunes.org
Sun Jun 8 16:13:56 CEST 2003


Hello Michael,

On Sat, Jun 07, 2003 at 08:38:32PM +0100, Michael Hudson wrote:
> try:
>     "x" + 1
> except TypeError, e:
>     raise e
> 
> because here 'e' gets bound to a *string* and then this is what's
> reraised.

This is the same problem as in CPython. Most failing internal operations call
PyErr_SetString(), which causes a string to be used as the exception value.
The hack is that when the user code reaches an 'except' clauses the exception
is "normalized", which translates the pair "TypeError class + string" into the
pair "TypeError class + TypeError instance".

We might either choose to mimic this behavior or clean it up a bit, e.g. by
always using internally a single object as the exception instance. String
exceptions are being deprecated, but still we could reasonably emulate them,
say by inventing a StringException class. This would isolate the hacky parts
around this specific class (like setting sys.exc_type to something else than
current_exception.__class__ for this particular case).


A bientôt,

Armin.



More information about the Pypy-dev mailing list