Pattern: Custom exception does not inherit Exception
Issue: -
All built-in, non-system-exiting exceptions are derived from Exception
. All user-defined exceptions should also be derived from this class.
Example of incorrect code:
# Does not inherit from Exception
class CustomException(object):
pass
try:
1 + 1
except CustomException:
print("caught")
Example of correct code:
class CustomException(Exception):
pass
try:
1 + 1
except CustomException:
print("caught")