Skip to content

Instantly share code, notes, and snippets.

@venuktan
Created January 22, 2016 19:53
Show Gist options
  • Save venuktan/9fa14e84d806dd1f9a30 to your computer and use it in GitHub Desktop.
Save venuktan/9fa14e84d806dd1f9a30 to your computer and use it in GitHub Desktop.
python_error_printing
def PrintException():
exc_type, exc_obj, tb = sys.exc_info()
f = tb.tb_frame
lineno = tb.tb_lineno
filename = f.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment