[Python-Dev] Deprecating string exceptions

Guido van Rossum guido@python.org
Sat, 06 Apr 2002 09:00:24 -0500

> I'm not sure what the base class(es) actually buys us.  We could just
> as well say by fiat that the interpreter will set the traceback
> attribute of an exception instance to the traceback.  Why do we need a
> special base class to accomplish that?  This is Python.  You don't
> need to do isinstance().  You just need to see if it has the right
> attributes.

Fair enough, though having a common base class makes it easier to
augment the functionality -- every exception class would automatically
inherit any functionality provided by the base class.

But here's the real reason (which I brought up when we had this
discussion a few weeks ago but didn't remember completely last night):
once we reach the nirvana where all exceptions derive from Exception,
we can declare that


is equivament to

    except Exception:

and then, when we also store the traceback on the exception object, we
can (eventually) get rid of sys.exc_info().

> BTW, what is the signature for Exception.__init__()?  I've written
> many exception classes, often subclasses of some other exception, but
> I've hardly ever paid attention to the superclass __init__().  It
> usually suffices to set the right attributes.

It's been a documented recommended practice to inherit from Exception
since the introduction of class exceptions.  Why are you suddenly
fighting this?

--Guido van Rossum (home page: http://www.python.org/~guido/)