StandardError in Python 2 -> 3

Discussion in 'Python' started by Steven D'Aprano, Nov 17, 2012.

  1. The exception hierarchy in Python 3 is shallower than in Python 2.

    Here is a partial list of exceptions in Python 2:


    BaseException
    +-- SystemExit
    +-- KeyboardInterrupt
    +-- GeneratorExit
    +-- Exception
    +-- StandardError
    | +-- AttributeError
    | +-- ImportError
    | +-- NameError
    | +-- TypeError
    | +-- ValueError
    +-- Warning

    and the same again in Python 3:

    BaseException
    +-- SystemExit
    +-- KeyboardInterrupt
    +-- GeneratorExit
    +-- Exception
    +-- AttributeError
    +-- ImportError
    +-- NameError
    +-- SystemError
    +-- TypeError
    +-- ValueError
    +-- Warning


    Note that StandardError is gone.

    Does anyone use StandardError in their own code? In Python 2, I normally
    inherit from StandardError rather than Exception. Should I stop and just
    inherit from Exception in both 2 and 3?


    --
    Steven
    Steven D'Aprano, Nov 17, 2012
    #1
    1. Advertising

  2. Steven D'Aprano

    Ian Kelly Guest

    On Fri, Nov 16, 2012 at 6:30 PM, Steven D'Aprano
    <> wrote:
    > Does anyone use StandardError in their own code? In Python 2, I normally
    > inherit from StandardError rather than Exception. Should I stop and just
    > inherit from Exception in both 2 and 3?


    According to the docs, StandardError is for built-in exceptions, and
    user-defined exceptions are meant to inherit from Exception.

    http://docs.python.org/2/library/exceptions.html#exceptions.Exception
    Ian Kelly, Nov 17, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antoon Pardon
    Replies:
    3
    Views:
    258
    Steven Bethard
    Mar 6, 2006
  2. Replies:
    0
    Views:
    715
  3. Paul Moore
    Replies:
    0
    Views:
    589
    Paul Moore
    Mar 1, 2008
  4. Martin v. Löwis
    Replies:
    0
    Views:
    626
    Martin v. Löwis
    Mar 1, 2008
  5. Senthil Kumaran
    Replies:
    0
    Views:
    544
    Senthil Kumaran
    Jan 17, 2011
Loading...

Share This Page