e.printStackTrace相当于python [英] e.printStackTrace equivalent in python

查看:232
本文介绍了e.printStackTrace相当于python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 print(e)(其中e是一个例外)打印发生的异常
,但是我试图找到python等效的Java e.printStackTrace()将该异常精确地跟踪到它发生的行,并打印整个跟踪。

I know that print(e) (where e is an Exception) prints the occurred exception but, I was trying to find the python equivalent of Java's e.printStackTrace() that exactly traces the exception to what line it occurred and prints the entire trace of it.

任何人都可以在Python中告诉我相当于 e.printStackTrace()

Could anyone please tell me the equivalent of e.printStackTrace() in Python?

推荐答案

import traceback
traceback.print_exc()

当在中执行此操作时,除了...:阻止它将自动使用当前的异常。有关详细信息,请参阅 http://docs.python.org/library/traceback.html

When doing this inside an except ...: block it will automatically use the current exception. See http://docs.python.org/library/traceback.html for more information.

这篇关于e.printStackTrace相当于python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆