[Python-Dev] Mutable exceptions? (was Re: PEP 293, Codec Error Handling Callbacks)

Barry A. Warsaw barry@python.org
Thu, 15 Aug 2002 14:21:38 -0400


>>>>> "A" == Aahz  <aahz@pythoncraft.com> writes:

    >> "M.-A. Lemburg" <mal@lemburg.com> writes:
    >> What ? That exceptions are immutable ? I think it's a big win
    >> that exceptions are in fact mutable -- they are great for
    >> transporting extra information up the chain...
    >> I see. So this is an open issue.

    A> This looks like an issue that potentially deserves more
    A> community feedback, so I'm ripping it out and starting a new
    A> thread: should exception objects be treated as mutable as
    A> exceptions get caught and re-raised?

    A> (I'm not suggesting any code changes, just trying to get a feel
    A> for what "standard practice" ought to be, partly for the book
    A> I'm writing.)

MAL's right, it /is/ occasionally useful to do this.  A call higher up
the chain may have more information about the failing condition, and
it can be useful to augment the exception object with this extra
information.  That's one of the reasons why exception classes are so
much nicer than exception strings!

-Barry