如果错误没有被捕获,它就会一直往上抛,最后被Python解释器捕获,打印一个错误信息,然后程序退出
通过错误信息,可以追根溯源查到最终的错误原因
def foo(s): return 10 / int(s) def bar(s): return foo(s) * 2 def main(): bar('0') main() #输出: Traceback (most recent call last): File "err.py", line 11, in <module> main() File "err.py", line 9, in main bar('0') File "err.py", line 6, in bar return foo(s) * 2 File "err.py", line 3, in foo return 10 / int(s) ZeroDivisionError: division by zero