Change option for NewtonSolver when solver doesn't converge

I am running a time dependent code, and I know that over time the equations are becoming singular so that the solver will not converge. Unfortunately, when NewtonSolver doesn’t converge, the code stops executing. Is there an option for NewtonSolver that will simply pass a non-convergence flag to the main code, so that I can post process to get more information about what is happening? In particular, I would like to know what the last time was when the code did converge.

I would recommend writing your own newton/nonlinear solver. You can look at the corresponding tutorial for dolfinx or this example for dolfin for an inspiration.

There is Also an option:
https://github.com/search?q=repo%3AFEniCS%2Fdolfinx%20error_on_nonconvergence&type=code
that can be passed to the dolfinx Newton solver

Wouldn’t this link be the easiest way?

It is unclear to me what version of FEniCS you are using, as you haven’t specified it.
You could of course intercept the error and do whatever you would like.