我正在尝试使用rope
包进行一些重构。根据代码,它可能会抛出异常,并且有超过10个例外情况。
我不想做
from rope.base.exceptions import *
try:
# do something
except (AttributeNotFoundError, ModuleDecodeError,
..., ..., ..., RefactoringError) as e:
# do something else
我只想抓住所有绳索异常,就像这样
import rope
try:
# do something
except rope.base.exceptions.*:
# do something else
如何捕获特定模块的所有异常?
答案 0 :(得分:4)
抓住所有例外的基础:
In [5]: import rope.base.exceptions as rbe
In [6]: try:
...: raise rbe.AttributeNotFoundError
...: except rbe.RopeError, e:
...: print "RopeError -", e
...:
RopeError!