python exceptions


Author: yifei / Created: May 30, 2017, 11:01 a.m. / Modified: May 30, 2017, 11:04 a.m. / Edit

User defined class

for user defined exceptions, just subclass Exception

Catching Exceptions

except Exception as e: # SystemExit, KeyboardInterrupt, GeneratorExit is not captured
    log('Reason', e)    # the baseline is to record

Built-in Exceptions

BaseException
 +-- SystemExit
 +-- *KeyboardInterrupt*
 +-- GeneratorExit
 +-- Exception
      +-- *StopIteration*
      +-- *StandardError*
      |    +-- BufferError
      |    +-- *ArithmeticError*
      |    |    +-- FloatingPointError
      |    |    +-- OverflowError
      |    |    +-- ZeroDivisionError
      |    +-- AssertionError
      |    +-- AttributeError
      |    +-- EnvironmentError
      |    |    +-- *IOError*
      |    |    +-- OSError
      |    |         +-- WindowsError (Windows)
      |    |         +-- VMSError (VMS)
      |    +-- EOFError
      |    +-- *ImportError*
      |    +-- *LookupError*
      |    |    +-- IndexError
      |    |    +-- KeyError
      |    +-- MemoryError
      |    +-- *NameError*
      |    |    +-- UnboundLocalError
      |    +-- ReferenceError
      |    +-- RuntimeError
      |    |    +-- NotImplementedError
      |    +-- *SyntaxError*
      |    |    +-- IndentationError
      |    |         +-- TabError
      |    +-- SystemError
      |    +-- *TypeError*
      |    +-- *ValueError*
      |         +-- UnicodeError
      |              +-- UnicodeDecodeError
      |              +-- UnicodeEncodeError
      |              +-- UnicodeTranslateError
      +-- *Warning*
           +-- DeprecationWarning
           +-- PendingDeprecationWarning
           +-- RuntimeWarning
           +-- SyntaxWarning
           +-- UserWarning
           +-- FutureWarning
       +-- ImportWarning
       +-- UnicodeWarning
       +-- BytesWarning

评论区