Skip to content
Advertisement

Can you continue to run code post Runtime Error?

My code scans through folders and for every folder plots a graph. However at the moment when using my curve fitting code for one of the graphs it produces a runtime error code as:

RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 5000.

This is annoying because it stops the code and stops the scanning of subsequent folders. Is there any way for the code once the runtime error occurs for it to just skip that snippet of code? So that the rest of the folders are scanned and the subsequent graphs produced.

Advertisement

Answer

Yes, put the code in try block.

try: (CODE TO TRY) except Exception: (Code to execute if error)

https://docs.python.org/3/tutorial/errors.html

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement