Skip to main content
100%

Python debugging an exception

✓ Published0🌍 Public
WWilliamQLiu
Last edited Feb 17, 2017
Created on Feb 17, 2017

This example shows a minimal Python script that demonstrates how to catch and format an exception. It deliberately triggers an exception by assigning `1` to `temp` after initially setting it to `None`, then uses `sys.exc_info()` to retrieve the exception type, value, and traceback. The code prints both the string and representation of the exception, and finally formats the full traceback with `traceback.format_exception()`. The output displays the error message and stack trace in the console, illustrating the standard workflow for handling and reporting exceptions in Python.

AI-generated description

Similar vizzes