我正在使用一个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
异常吗?欢迎提供任何提示!