Is there a way to trace while running the program?

Asked 2 years ago, Updated 2 years ago, 73 views

I'm creating a program that receives files from the website and reads the data as numpy. But when I receive the file, there are countless errors due to strange links or wrong xml structures ㅜ<

I'd like to make an exception by saving the error message log that comes out when there is no exception in the text file and reviewing it all at once later If you write the code below together, you don't know where the error came from, and other information disappears, so only almost useless data continues to be printed.

try:
    do_stuff()
except Exception, err:
    print Exception, err

How do I know exactly where the error occurred in which module?

python exception-handling

2022-09-21 20:13

1 Answers

traceback.format_exc() or sys.exc_info()

Example:

import traceback
import sys

try:
    do_stuff() #What code
except Exception, err:
    print(traceback.format_exc())
    #or
    print(sys.exc_info()[0])


2022-09-21 20:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.