Skip to content

Instantly share code, notes, and snippets.

@chendi0x7C00
Created January 10, 2017 15:15
Show Gist options
  • Save chendi0x7C00/3dc98a466a9e677299d00ba206f497d1 to your computer and use it in GitHub Desktop.
Save chendi0x7C00/3dc98a466a9e677299d00ba206f497d1 to your computer and use it in GitHub Desktop.
use traceback module to get more stackinfo when Exception occus
# coding:UTF-8
import sys
import traceback
def a():
print("a")
b()
def b():
print("b")
try:
c()
except Exception as e:
print("="*90)
traceback.print_exc() # 1
print("="*90)
sys.stderr.write(traceback.format_exc()) # 2
sys.stderr.flush()
print("="*90)
type, val, tb = sys.exc_info() # 3
print(type)
print(val)
for filename, linenum, funcname, source in traceback.extract_tb(tb):
print(filename, linenum, funcname, source)
def c():
print("c")
raise IndexError("some error")
def main():
a()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment