How to get a list of built-in exceptions in python

Step 1: Create a python file that looks like this:

print_exc_tree.py


from __future__ import print_function
import platform


def classtree(cls, depth=0):
    if depth == 0:
        prefix = ''
    else:
        prefix = '.' * (depth * 3) + ' '
    if cls.__name__.lower() == 'error':
        print('{0}{1} ({2})'.format(prefix, cls.__name__, cls))
    else:
        print('{0}{1}'.format(prefix, cls.__name__))
    for subcls in sorted(cls.__subclasses__(), key=lambda c: c.__name__):
        classtree(subcls, depth+1)


if __name__ == '__main__':
    print('Python Version: {0}'.format(platform.python_version()))
    print()
    classtree(BaseException)

Step 2: After creating the above python file, enter the following code at the command prompt.

python  print_exc_tree.py

Step 3: You can get a list of python built-in exceptions as follows:

Python Version: 3.7.4

BaseException
... Exception
...... ArithmeticError
......... FloatingPointError
......... OverflowError
......... ZeroDivisionError
...... AssertionError
...... AttributeError
...... BufferError
...... EOFError
...... Error (<class 'locale.Error'>)
...... ImportError
......... ModuleNotFoundError
......... ZipImportError
...... LookupError
......... CodecRegistryError
......... IndexError
......... KeyError
...... MemoryError
...... NameError
......... UnboundLocalError
...... OSError
......... BlockingIOError
......... ChildProcessError
......... ConnectionError
............ BrokenPipeError
............ ConnectionAbortedError
............ ConnectionRefusedError
............ ConnectionResetError
......... FileExistsError
......... FileNotFoundError
......... InterruptedError
......... IsADirectoryError
......... NotADirectoryError
......... PermissionError
......... ProcessLookupError
......... TimeoutError
......... UnsupportedOperation
...... ReferenceError
...... RuntimeError
......... BrokenBarrierError
......... NotImplementedError
......... RecursionError
......... _DeadlockError
...... StopAsyncIteration
...... StopIteration
...... StopTokenizing
...... SubprocessError
......... CalledProcessError
......... TimeoutExpired
...... SyntaxError
......... IndentationError
............ TabError
...... SystemError
......... CodecRegistryError
...... TokenError
...... TypeError
...... ValueError
......... UnicodeError
............ UnicodeDecodeError
............ UnicodeEncodeError
............ UnicodeTranslateError
......... UnsupportedOperation
...... Verbose
...... Warning
......... BytesWarning
......... DeprecationWarning
......... FutureWarning
......... ImportWarning
......... PendingDeprecationWarning
......... ResourceWarning
......... RuntimeWarning
......... SyntaxWarning
......... UnicodeWarning
......... UserWarning
...... _OptionError
...... error (<class 're.error'>)
... GeneratorExit
... KeyboardInterrupt
... SystemExit

Recommended Posts

How to get a list of built-in exceptions in python
How to get a stacktrace in python
How to get the last (last) value in a list in Python
How to get a list of files in the same directory with python
How to clear tuples in a list (Python)
Try to get a list of breaking news threads in Python.
[Python] How to put any number of standard inputs in a list
How to format a list of dictionaries (or instances) well in Python
How to get the number of digits in Python
How to write a list / dictionary type of Python3
How to pass the execution result of a shell command in a list in Python
How to shuffle a part of a Python list (at random.shuffle)
Get the number of specific elements in a python list
Developed a library to get Kindle collection list in Python
I tried "How to get a method decorated in Python"
How to develop in a virtual environment of Python [Memo]
How to get a list of links from a page from wikipedia
How to get a quadratic array of squares in a spiral!
[Python] How to convert a 2D list to a 1D list
Display a list of alphabets in Python 3
[python] Get a list of instance variables
Summary of built-in methods in Python list
Summary of how to use Python list
[Python] Get a list of folders only
How to identify the element with the smallest number of characters in a Python list?
How to check in Python if one of the elements of a list is in another list
How to determine the existence of a selenium element in Python
How to check the memory size of a variable in Python
How to get a string from a command line argument in python
How to check the memory size of a dictionary in Python
How to get the vertex coordinates of a feature in ArcPy
How to delete multiple specified positions (indexes) in a Python list
Get a list of files in a folder with python without a path
Get the value of a specific key up to the specified index in the dictionary list in Python
[Python] How to delete rows and columns in a table (list of drop method options)
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to embed a variable in a python string
Summary of how to import files in Python 3
Get the caller of a function in Python
How to create a JSON file in Python
Make a copy of the list in Python
Summary of how to use MNIST in Python
How to notify a Discord channel in Python
How to get dictionary type elements of Python 2.7
How to get the files in the [Python] folder
Get a glimpse of machine learning in Python
[Python] How to draw a histogram in Matplotlib
How to remove duplicate elements in Python3 list
Get a list of packages installed in your current environment with python
How to send a visualization image of data created in Python to Typetalk
[Introduction to Python] How to sort the contents of a list efficiently with list sort
How to get a value from a parameter store in lambda (using python)
[Python] How to use list 1
How to develop in Python
How to convert / restore a string with [] in python
How to get the variable name itself in python
[python] Get the list of classes defined in the module
[Python] How to expand variables in a character string
Things to note when initializing a list in Python
[Python] How to sort dict in list and instance in list
Python: Get a list of methods for an object