标签:style blog color io os ar 数据 div sp
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
raise <异常类>
raise <异常类> , <附加数据>
assert <条件表达式>, <附加数据> 如果条件表达式为假,则抛出异常
1 #-*- coding: utf-8 -*- 2 3 #自定义异常类 4 class AuditException(Exception): 5 def __init__(self, data): 6 self.data = data 7 8 def __str__(self): 9 return self.data 10 11 12 13 if __name__ == "__main__": 14 try: 15 raise AuditException, "The audit operation is not exist." 16 except AuditException, data: 17 print data #The audit operation is not exist. 18 19 #或者 20 21 try: 22 raise AuditException, "The audit operation is not exist." 23 except: 24 import traceback 25 traceback.print_exc() 26
try: #do something except: #如果引发了异常,do something else: #如果未发生异常,do something
try: #do something finally: #不管有没有异常,do something
标签:style blog color io os ar 数据 div sp
原文地址:http://www.cnblogs.com/zhouwenhong/p/3967424.html