1、多用断言assert,有个断言异常AssertionError:断言语句(assert)失败
2、try except 处理异常
try: 检测范围 except Exception[as reason]: 出现异常后的处理代码
3、
try: 检测范围 except Exception[as reason]: 出现异常后的处理代码 finally: 无论如何都会被执行的代码
try: 检测范围 except(Exception1[, Exception2[,...ExceptionN]]]): 发生以上多个异常中的一个,执行这块代码 else: 如果没有异常执行这块代码
Python 使用raise
语句抛出一个指定的异常。