Created
October 2, 2012 12:30
-
-
Save niwinz/3818659 to your computer and use it in GitHub Desktop.
What is the simplest way of using Python pdb to inspect the cause of an unhandled exception?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import pdb | |
def debug_on(*exceptions): | |
if not exceptions: | |
exceptions = (AssertionError, ) | |
def decorator(f): | |
@functools.wraps(f) | |
def wrapper(*args, **kwargs): | |
try: | |
return f(*args, **kwargs) | |
except exceptions: | |
pdb.post_mortem(sys.exc_info()[2]) | |
return wrapper | |
return decorator | |
# example | |
@debug_on(TypeError) | |
def buggy_function() | |
.... | |
raise TypeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment