【发布时间】:2018-01-25 21:05:36
【问题描述】:
我正在使用一个 python 库,其中有一次异常定义如下:
raise Exception("Key empty")
我现在希望能够捕获该特定异常,但我不知道该怎么做。
我尝试了以下
try:
raise Exception('Key empty')
except Exception('Key empty'):
print 'caught the specific exception'
except Exception:
print 'caught the general exception'
但这只是打印出caught the general exception。
有人知道我如何捕捉特定的Key empty 异常吗?欢迎所有提示!
【问题讨论】:
标签: python exception try-catch