See the traceback
module, specifically the format_exc()
function. Here.
import traceback
try:
raise ValueError
except ValueError:
tb = traceback.format_exc()
else:
tb = "No error"
finally:
print tb
More Related Contents:
- When I catch an exception, how do I get the type, file, and line number?
- How to save traceback / sys.exc_info() values in a variable?
- Catching exception in context manager __enter__()
- Can Syntax Errors be handled?
- Can Syntax Errors be handled?
- How do I properly start creating a programming language in python? [closed]
- Manually raising (throwing) an exception in Python
- django MultiValueDictKeyError error, how do I deal with it
- How to use pip with Python 3.x alongside Python 2.x
- How do you create nested dict in Python?
- Python: How to get stdout after running os.system? [duplicate]
- board-drawing code to move an oval
- Remove text between () and []
- Convert timedelta64[ns] column to seconds in Python Pandas DataFrame
- Inserting a table name into a query gives sqlite3.OperationalError: near “?”: syntax error
- Selenium Webdriver in Python – files download directory change in Chrome preferences
- Pygame2Exe Errors that I can’t fix
- Reading a file with a specified delimiter for newline
- class method generates “TypeError: … got multiple values for keyword argument …”
- Easier way to enable verbose logging
- Try/catch or validation for speed?
- WinError 2 The system cannot find the file specified (Python)
- Python FAQ: “How fast are exceptions?”
- How do I make the screen ignore the background color of some image?
- Reading serial data in realtime in Python
- range(len(list)) or enumerate(list)? [duplicate]
- python sys.exit not working in try [duplicate]
- How do I create a directory, and any missing parent directories?
- Converting string to tuple without splitting characters
- How does all() in python work on empty lists