Skip to content

Instantly share code, notes, and snippets.

@sashadev-sky
Last active March 23, 2021 20:32
Show Gist options
  • Save sashadev-sky/7ac159a145f923d4a1dcbc4132e87beb to your computer and use it in GitHub Desktop.
Save sashadev-sky/7ac159a145f923d4a1dcbc4132e87beb to your computer and use it in GitHub Desktop.
Useful exception tree reference for Python3
def print_exceptions_tree(exception_class, level=0):
if level > 1:
print(" |" * (level - 1), end="")
if level > 0:
print(" +---", end="")
print(exception_class.__name__)
for subclass in exception_class.__subclasses__():
print_exceptions_tree(subclass, level + 1)
print_exceptions_tree(BaseException)
~/GreedyGoodnaturedPlot$ python3 exceptions_tree.py
BaseException
+---Exception
| +---TypeError
| +---StopAsyncIteration
| +---StopIteration
| +---ImportError
| | +---ModuleNotFoundError
| | +---ZipImportError
| +---OSError
| | +---ConnectionError
| | | +---BrokenPipeError
| | | +---ConnectionAbortedError
| | | +---ConnectionRefusedError
| | | +---ConnectionResetError
| | +---BlockingIOError
| | +---ChildProcessError
| | +---FileExistsError
| | +---FileNotFoundError
| | +---IsADirectoryError
| | +---NotADirectoryError
| | +---InterruptedError
| | +---PermissionError
| | +---ProcessLookupError
| | +---TimeoutError
| | +---UnsupportedOperation
| | +---ItimerError
| +---EOFError
| +---RuntimeError
| | +---RecursionError
| | +---NotImplementedError
| | +---_DeadlockError
| +---NameError
| | +---UnboundLocalError
| +---AttributeError
| +---SyntaxError
| | +---IndentationError
| | | +---TabError
| +---LookupError
| | +---IndexError
| | +---KeyError
| | +---CodecRegistryError
| +---ValueError
| | +---UnicodeError
| | | +---UnicodeEncodeError
| | | +---UnicodeDecodeError
| | | +---UnicodeTranslateError
| | +---UnsupportedOperation
| +---AssertionError
| +---ArithmeticError
| | +---FloatingPointError
| | +---OverflowError
| | +---ZeroDivisionError
| +---SystemError
| | +---CodecRegistryError
| +---ReferenceError
| +---MemoryError
| +---BufferError
| +---Warning
| | +---UserWarning
| | +---DeprecationWarning
| | +---PendingDeprecationWarning
| | +---SyntaxWarning
| | +---RuntimeWarning
| | +---FutureWarning
| | +---ImportWarning
| | +---UnicodeWarning
| | +---BytesWarning
| | +---ResourceWarning
| +---Error
| +---_OptionError
+---GeneratorExit
+---SystemExit
+---KeyboardInterrupt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment