0

I currently use this structure for capturing and recording my exception handling

1.  import sys
2.
3.  def break_python():
4.      test1 = 1/0
5.
6.  def main():
7.     #All main program functionality is included in this section
8.     break_python()
9.  
10. if __name__ == "__main__":
11.     try:
12.         main()
13.     except Exception as e:
14.         print dir(e)
15.         print e.message
16.         type1,details,tb = sys.exc_info_()
17.         print type1
18.         print details
19.         print tb
20.         line_no = tb.tb_lineno
21.         print "Line # " + str(line_no)
22.         print "Failed to run program"

When I run this as my primary program structure everything works however the line number will print as line 12 corresponding to the main() function call when I really want it to point to the function and line number of the individual error, in this case line 4 under function break_python()

1 Answer 1

2

I think you are looking for traceback.print_exc(file=sys.stdout) See https://docs.python.org/2/library/traceback.html#traceback-examples

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.