def handle(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: print('sfdsd') return wrapper @handle #捕获异常,后面语句继续执行 def test(): r = 1 / 0 #引发异常 print(111) test() print('sdf')#如果异常不处理后面的语句将不会执行
def handle(func): def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: print('sfdsd') return wrapper @handle #捕获异常,后面语句继续执行 def test(): r = 1 / 0 #引发异常 print(111) test() print('sdf')#如果异常不处理后面的语句将不会执行