Python logoPython/
PYL-E0712

Exception caught which does not inherit from `Exception`PYL-E0712

Critical severityCritical
Bug Risk categoryBug Risk

For an exception to be caught, it must inherit from the Exception class.

Bad practice

try:
    if foo < 5:
        print('foo is small')
except NotImplemented:  # This is not an error class!
    print('Some error occured')

Bad practice

try:
    if foo < 5:
        print('foo is small')
except NotImplementedError:  # This is a valid error class
    print('Some error occured')