Schritt 1: Erstellen Sie eine Python-Datei, die folgendermaßen aussieht:
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)
Schritt 2: Geben Sie nach dem Erstellen der obigen Python-Datei an der Eingabeaufforderung den folgenden Code ein.
python print_exc_tree.py
Schritt 3: Sie können eine Liste der in Python integrierten Ausnahmen wie folgt abrufen:
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