import sys, os
try:
raise NotImplementedError("No error")
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
More Related Contents:
- Showing the stack trace from a running Python application
- How to catch and print the full exception traceback without halting/exiting the program?
- Python: Getting a traceback from a multiprocessing.Process
- How can I more easily suppress previous exceptions when I raise my own exception in response?
- Get exception description and stack trace which caused an exception, all as a string
- Print an error message without printing a traceback and close the program when a condition is not met
- Catch and print full Python exception traceback without halting/exiting the program
- Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name”
- Is it a good practice to use try-except-else in Python?
- Catch a thread’s exception in the caller thread?
- selenium.common.exceptions.InvalidSelectorException with “span:contains(‘string’)”
- 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
- 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__()
- Multiple try codes in one block
- Extract traceback info from an exception object