Search code examples
pythonscipy-optimize

What if I want to continue my code when this problem come out? RuntimeError: Optimal parameters not found


My code is too long and I don't want to solve this error, because of the flaws of original data.
The error is:
RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 50000.
This error come out when iterations = maxfev. What I want to do is: when the iterations = maxfev, don't shut down the code, but to continue operating next pack of data. For example:

if raise RuntimeError :
   data = data
else:
   data = data-1

Something like that.
I just don't want the program to stop.
I don't know did I say clearly? Ask me if you need any details.


Solution

  • You can do it like this.

    try:
        somecode
    except RuntimeError as err:
        print('error')
        data = data
        raise err
    else:
        print('no error')
        data = data - 1