Skip to content

Instantly share code, notes, and snippets.

@dhuseby
Last active August 29, 2015 13:57
Show Gist options
  • Save dhuseby/9696993 to your computer and use it in GitHub Desktop.
Save dhuseby/9696993 to your computer and use it in GitHub Desktop.
Precise Python Exception Messages
#!/bin/env python
"""
Exceptions that give more precise error messages.
"""
import sys, inspect
def main():
try:
# your application code
except Exception, e:
frame = inspect.trace()[-1]
print >> sys.stderr, "Exception:\n from %s, line %d:\n %s" % (frame[1], frame[2], e)
sys.exit(1)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment