Skip to content

Instantly share code, notes, and snippets.

@Highstaker
Last active May 23, 2016 17:07
Show Gist options
  • Save Highstaker/1ed6dd8f95cd8ed515f42681c1c8cd6f to your computer and use it in GitHub Desktop.
Save Highstaker/1ed6dd8f95cd8ed515f42681c1c8cd6f to your computer and use it in GitHub Desktop.
A function that prints the full traceback
#!/usr/bin/python3 -u
# -*- coding: utf-8 -*-
import sys, traceback
def full_traceback():
"""
Returns a full traceback to an exception
:return:
"""
exc_type, exc_value, exc_traceback = sys.exc_info()
a = traceback.format_exception(exc_type, exc_value, exc_traceback)
a = "".join(a)
return a
if __name__ == '__main__':
# A quick test
def a():
raise KeyError
def b():
return a()
try:
b()
except KeyError:
print(full_traceback())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment