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:
- How to catch and print the full 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
- Manually raising (throwing) an exception in Python
- I’m getting an IndentationError. How do I fix it?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- django MultiValueDictKeyError error, how do I deal with it
- Showing the stack trace from a running Python application
- How to retry after exception?
- SyntaxError inconsistency in Python?
- Catch exception and continue try block in Python
- Bad idea to catch all exceptions in Python
- How to get exception message in Python properly
- 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?
- hasattr() vs try-except block to deal with non-existent attributes
- One try block with multiple excepts
- How to re-raise an exception in nested try/except blocks?
- Get Traceback of warnings
- Try/catch or validation for speed?
- How to return a custom 404 Not Found page using FastAPI?
- Re-raise exception with a different type and message, preserving existing information
- Catching exception in context manager __enter__()
- Extract traceback info from an exception object