0 votes
1 view
in Java by (3.9k points)
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.

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

1 Answer

0 votes
by (46.1k points)

import traceback

traceback.print_exc()

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.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 9, 2019 in Java by Nigam (4.1k points)
0 votes
1 answer
asked Jul 9, 2019 in Java by Aditya98 (1.3k points)
0 votes
1 answer
asked Feb 20, 2020 in Java by angadmishra (6.5k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...