Re-raising exceptions with a different type and message, preserving existing information

Aahz aahz at pythoncraft.com
Sun Apr 5 15:28:10 EDT 2009


In article <87ljqnpo6o.fsf at benfinney.id.au>,
Ben Finney  <ben+python at benfinney.id.au> wrote:
>
>What I need is to “wrap” the exception caught such that it has a
>different type and message. But I don't want to lose the existing
>type, message, and stack trace; that's all useful information for
>someone trying to debug the problem.
>
>Python's PEP 3134 “Exception Chaining and Embedded Tracebacks”
>discusses a change accepted in Python 3.0 for “chaining” exception
>objects, to indicate that a new exception was raised during the
>handling of an existing exception.
>
>What I'm trying to do is related: I need it working in earlier Python
>versions, and I need it not for chaining, but only for polymorphism.
>What is the right way to do this?

The same way that 3.0 does it, IMO.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"...string iteration isn't about treating strings as sequences of strings, 
it's about treating strings as sequences of characters.  The fact that
characters are also strings is the reason we have problems, but characters 
are strings for other good reasons."  --Aahz



More information about the Python-list mailing list