与抽象:
def log_it(): try: 1 / 0 except: passtry: this = thatexcept: log_it() raise
可以在Python 2.5中做到吗
另一种方法是将异常存储在变量中,然后显式重新引发它:
try: this = thatexcept NameError, e: # or NameError as e for Python 2.6 try: 1 / 0 except: pass raise e
请注意,您可能不应该仅仅使用裸机
except来捕获可能发生的所有事情,通常最好是捕获您期望发生的特定异常,以防发生严重而致命的异常(例如内存不足)。



