我希望以特定方式处理某个异常,并一般性地记录所有其他异常。以下是我的代码:
class MyCustomException(Exception): pass
try:
something()
except MyCustomException:
something_custom()
except Exception as e:
#all others
logging.error("{}".format(e))
问题在于即使是
MyCustomException
也会被记录,因为它继承自Exception
。我该如何避免这种情况?
something()
中引发了一个MyCustomException
,那么这段代码就能正常工作。你是如何在something()
中引发异常的? - Henrik Andersson