I know about the possibility to stop the debugger on unhandled exceptions (python exception breakpoint) which works great when a code produces an unexpected error. However, this functionality requires my script to run in "debugging mode", which is much slower than "run mode" and may require hours before generating the error. How can I handle unexpected errors in run mode?
So far, my poor solution is to:
1. Run the script in run mode
2. Wait for the error
3. Attach the debugger from the console
4. Manually call the function where the error was generated
5. Finally debug
However, this solution doesn't work if the function itself triggering the error is slow. In that case, I'll have to wait for the function to run twice, once in "run mode" and once again with the debugger attached, and this is very impractical for scientific calculations.
Another possible solution is to write the entire script without using functions and run the code in "run mode", without using the debugger at all. If an error happens, I'll still be able to save my results using the console and investigate the cause of the error.
Is there a proper way to deal with this problem? Can I attach the debugger on unhandled error and then stop the debugger on the same line?