python3中简单的异常捕获及显示堆栈调用

import traceback
def fun(a,b):
    return a/b
try:
    fun(1,0)
except Exception as e:
    traceback.print_exc()

从根本上来说 traceback是从sys.exc_info获取的信息
详见:
http://blog.csdn.net/lengxingxing_/article/details/56317838
http://blog.csdn.net/pipisorry/article/details/47907589

你可能感兴趣的:(备忘)