Python錯誤類型及各自繼承關係

BaseException  # 父類
+-- SystemExit
+-- KeyboardInterrupt
+-- GeneratorExit
+-- Exception  # 常用
  +-- StopIteration
  +-- StopAsyncIteration
  +-- ArithmeticError
  |    +-- FloatingPointError
  |    +-- OverflowError
  |    +-- ZeroDivisionError
  +-- AssertionError
  +-- AttributeError
  +-- BufferError
  +-- EOFError
  +-- ImportError
  |    +-- ModuleNotFoundError
  +-- LookupError
  |    +-- IndexError
  |    +-- KeyError
  +-- MemoryError
  +-- NameError
  |    +-- UnboundLocalError
  +-- OSError
  |    +-- BlockingIOError
  |    +-- ChildProcessError
  |    +-- ConnectionError
  |    |    +-- BrokenPipeError
  |    |    +-- ConnectionAbortedError
  |    |    +-- ConnectionRefusedError
  |    |    +-- ConnectionResetError
  |    +-- FileExistsError
  |    +-- FileNotFoundError
  |    +-- InterruptedError
  |    +-- IsADirectoryError
  |    +-- NotADirectoryError
  |    +-- PermissionError
  |    +-- ProcessLookupError
  |    +-- TimeoutError
  +-- ReferenceError
  +-- RuntimeError
  |    +-- NotImplementedError
  |    +-- RecursionError
  +-- SyntaxError
  |    +-- IndentationError
  |         +-- TabError
  +-- SystemError
  +-- TypeError
  +-- ValueError
  |    +-- UnicodeError
  |         +-- UnicodeDecodeError
  |         +-- UnicodeEncodeError
  |         +-- UnicodeTranslateError
  +-- Warning
	+-- DeprecationWarning
	+-- PendingDeprecationWarning
	+-- RuntimeWarning
	+-- SyntaxWarning
	+-- UserWarning
	+-- FutureWarning
	+-- ImportWarning
	+-- UnicodeWarning
	+-- BytesWarning
	+-- ResourceWarning


try:
	expression
except <error_type> as e:
	print('<error_type>', e)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章