捕获自定义异常
此示例显示如何捕获自定义 Exception
class CustomError(Exception):
pass
try:
raise CustomError('Can you catch me ?')
except CustomError as e:
print ('Catched CustomError :{}'.format(e))
except Exception as e:
print ('Generic exception: {}'.format(e))
输出:
Catched CustomError :Can you catch me ?