个人博客
自定义异常
class MY(BaseException):
def __init__(self,msg):
super().__init__()
self.msg = msg
def __str__(self):
return f"{self.msg}"
try:
print(555555)
raise MY("666")
except MY as e: # 自定义异常需要自己捕获!!!
print(e)
import traceback
print(traceback.format_exc())
except Exception as e:
print(e)
# else:
# print("------------")