traceback.format_exc()
or sys.exc_info()
will yield more info if that’s what you want.
import traceback
import sys
try:
do_stuff()
except Exception:
print(traceback.format_exc())
# or
print(sys.exc_info()[2])
More Related Contents:
- Catch and print full Python exception traceback without halting/exiting the program
- Why is “except: pass” a bad programming practice?
- Is it a good practice to use try-except-else in Python?
- When I catch an exception, how do I get the type, file, and line number?
- Python: Getting a traceback from a multiprocessing.Process
- How can I more easily suppress previous exceptions when I raise my own exception in response?
- Python FAQ: “How fast are exceptions?”
- Print an error message without printing a traceback and close the program when a condition is not met
- Multiple try codes in one block
- Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name”
- Catch a thread’s exception in the caller thread?
- Better to ‘try’ something and catch the exception or test if it’s possible first to avoid an exception?
- How to print an exception in Python?
- How to retry after exception?
- SyntaxError inconsistency in Python?
- How to exit from Python without traceback?
- How to get exception message in Python properly
- Python type hinting with exceptions
- How can I make silent exceptions louder in tkinter?
- Is there a way to prevent a SystemExit exception raised from sys.exit() from being caught?
- How can I modify a Python traceback object when raising an exception?
- Python: How to ignore an exception and proceed? [duplicate]
- hasattr() vs try-except block to deal with non-existent attributes
- How to re-raise an exception in nested try/except blocks?
- Is there a difference between “raise exception()” and “raise exception” without parenthesis?
- Get Traceback of warnings
- Getting the exception value in Python
- raise statement on a conditional expression
- ‘sys.excepthook’ and threading
- Can Syntax Errors be handled?