Posted onIn技术
,
PythonViews: Word count in article: 908Reading time ≈1 mins.
自定义异常类,需要继承 BaseException
写了一个demo异常类,没有继承BaseException类,提示报如下错误,很明显只要继承一下BaseException就可以了。 TypeError: catching classes that do not inherit from BaseException is not allowed 捕获到一个没有继承BaseException的异常类(这是不被允许的)。
1 2 3 4
Exception ignored in: <generator object demo_exc_handling at 0x000001D06C66E200> Traceback (most recent call last): File "a5_3_coroutine_exception.py", line 10, in demo_exc_handling TypeError: catching classes that do not inherit from BaseException is not allowed