要用exception
下面的代码可以处理异常
try: # ‘65046A‘ bom = input(‘Pleaes enter bit BOM: ‘) if bom == ‘exit‘: break evaluate_bom(bom) except Exception as e: print(‘Error:‘, e) finally: pass
下面的代码不会
try: # ‘65046A‘ bom = input(‘Pleaes enter bit BOM: ‘) if bom == ‘exit‘: break evaluate_bom(bom) finally: pass
From the Python documentation:
If the finally clause raises another exception or executes a return or break statement, the saved exception is lost.
原文:https://www.cnblogs.com/andy-0212/p/9946867.html