StandardError in Python 2 -> 3

S

Steven D'Aprano

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top