11 lines
1.1 KiB
Plaintext
11 lines
1.1 KiB
Plaintext
In Python 3, attempting to catch in an ``++except++`` statement an object which does not derive from BaseException will raise a ``++TypeError++``. In Python 2 it is possible to raise old-style classes but this shouldn't be done anymore in order to be compatible with Python 3.
|
|
|
|
|
|
In order to catch multiple exceptions in an ``++except++`` statement, a tuple of exception classes should be provided.
|
|
|
|
|
|
If you are about to create a custom Exception class, note that custom exceptions should inherit from ``++Exception++``, not ``++BaseException++``. ``++Exception++`` allows people to catch all exceptions except the ones explicitly asking the interpreter to stop, such as ``++KeyboardInterrupt++`` and https://docs.python.org/3/library/exceptions.html#GeneratorExit[``++GeneratorExit++``] which is not an error. See https://www.python.org/dev/peps/pep-0352/#exception-hierarchy-changes[PEP 352] for more information.
|
|
|
|
|
|
This rule raises an issue when the expression used in an ``++except++`` statement is not a class deriving from ``++BaseException++`` nor a tuple of such classes.
|