1. 处理异常/捕获异常
try:
raise MyException("11")
except Exception as e:
print(e)
import traceback
try:
raise MyException("11")
except :
print(traceback.format_exc()) #捕获并回溯异常
2. 自定义异常
class MyException(Exception):
pass
try:
raise MyException("11")
except Exception as e:
print(e)
3. 常见异常
BaseException
SystemExit// KeyBoardInterrutp// GeneratorExit
Exception
4. 问题思考:
自定义异常为什么不继承BaseException?-----如果继承BaseException连KeyBoardInterrutp都会被捕获的