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])
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?
- Multiple try codes in one block
- How can I more easily suppress previous exceptions when I raise my own exception in response?
- Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name”
- How can I safely create a nested directory?
- Manually raising (throwing) an exception in Python
- Catch multiple exceptions in one line (except block)
- How do I check if a variable exists?
- Why does this iterative list-growing code give IndexError: list assignment index out of range?
- How can I write a `try`/`except` block that catches all exceptions?
- What is the intended use of the optional “else” clause of the “try” statement in Python?
- Catch a thread’s exception in the caller thread?
- How do you test that a Python function throws an exception?
- Should I always specify an exception type in `except` statements?
- Determine function name from within that function (without using traceback)
- Better to ‘try’ something and catch the exception or test if it’s possible first to avoid an exception?
- django MultiValueDictKeyError error, how do I deal with it
- How to print an exception in Python?
- How do I print an exception in Python?
- Capture keyboardinterrupt in Python without try-except
- Cost of exception handlers in Python
- How to retry after exception?
- Python global exception handling
- Python exception chaining [duplicate]
- “Inner exception” (with traceback) in Python?
- In Python, how does one catch warnings as if they were exceptions?
- How to exit from Python without traceback?
- How do I catch a numpy warning like it’s an exception (not just for testing)?
- How to get exception message in Python properly
- Exception thrown in multiprocessing Pool not detected
- Python type hinting with exceptions
- How do I determine what type of exception occurred?
- One try block with multiple excepts
- How can I safely create a directory (possibly including intermediate directories)?
- How do I raise the same Exception with a custom message in Python?
- How can I know which exceptions might be thrown from a method call?
- python exception message capturing
- How to get the name of an exception that was caught in Python?
- How to save traceback / sys.exc_info() values in a variable?
- Checking for member existence in Python
- Get exception description and stack trace which caused an exception, all as a string
- BaseException.message deprecated in Python 2.6
- BaseException.message deprecated in Python 2.6
- Is there a difference between “raise exception()” and “raise exception” without parenthesis?
- Get Traceback of warnings
- How do I create a directory, and any missing parent directories?
- How to return a custom 404 Not Found page using FastAPI?