Skip to content
Advertisement

How to print exception errors and trace tacks in a file when there’s an error in my code?

I want that whenever an error is raised in my code, traceback.print_exception() execute so I can have any errors in a file to check… Is it possible somehow?

Advertisement

Answer

You could try wrapping your code in a try/except block, and call the function in the except. It might look like this:

try:
    # Your code here
except Exception as e:
    traceback.print_exception(e)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement