假设我正在尝试做一些过程:
try:
# Do some process that can raise any number of exceptions
except NameError as ne:
logger.error('Caught NameError: {}'.format(ne))
except TypeError as te:
logger.error('Caught TypeError: {}'.format(ne))
except AttributeError as ae:
logger.error('Caught AttributeError: {}'.format(ne))
except:
logger.error('Something really bad happened...')
我有这个无所不包的逻辑,以确保我的服务不会失败,以防一些奇怪的异常无法处理(即大部分请求都被处理,以便我以后可以调试任何坏的) 。捕获这样的特定异常的规范方法是什么?如果我这样做了:
try:
# Do some process that can raise any number of exceptions
except Exception as e:
logger.error('Caught some Exception, but I don't know the base class... {}'.format(e))
我不知道这是一个NameError还是其他异常......