An easy way to view system-state when a differential equation solver encounters a warning

I am trying to solve a system of differential equations where I run into a larger Maxiters needed warning. I suspect that my model has been ill-specified as this appears only for certain parameter values. To figure this out, I would like to log my system state when the solver encounters this error. So far I have tried try-catch blocks, but they apparently don’t catch warnings but only errors.

Is there any neat way of implementing this?

Hello and welcome to the community :wave:

Isn’t the last recorded state in the solution object what you are looking for?

1 Like

Hey hey! Thank you!

I am not sure if that is the case. Even though I get this warning, the solver continues to run (sometimes I get the same error multiple times before the solver terminates).

If it’s a maxiters, then sol.u[end] would be that state that it ended on.

1 Like

False, alarm here. The solver does end after it reaches the maxiters error. I had quite simply forgotten about a loop the solver was in!