Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # try_linecache.py
- import linecache
- import sys
- def PrintException(err=None):
- 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)
- if err in [0,None]:
- print 'EXCEPTION IN LINE {} "{}"'.format(lineno, exc_obj)
- elif err == 1:
- print 'EXCEPTION IN LINE ', lineno
- elif err == 2:
- print 'EXCEPTION IN LINE {} "{}"'.format(lineno, line.strip())
- elif err == 3:
- print 'EXCEPTION IN LINE {} "{}": {}'.format(filename, lineno, line.strip(), exc_obj)
- elif err == 4:
- print 'EXCEPTION IN ({}, LINE {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)
- try:
- print 1/0
- except:
- PrintException()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement