Breaking only an inner for loop due to an error

Hi all. I’m trying to run a some code where I am intentionally pushing a differential equations solver that’s called inside a dynamic systems modeling package to fail to converge. I’m trying to explore the boundaries of when this failure happens and the system behavior near the boundary. When the solver fails I get an error that stops my code from advancing, which is fine, except it means I have to change my operating points manually which is time consuming.

I’m testing different combinations of variables which are in nested for loops, and I’d like the inner loop to run until the solver fails to converge in which case the code breaks to the outer loop to test the next set of conditions. Something like:

set_a = [3.0, 2.0, 1.0]
set_b = [0.25, 0.2, 0.15]
for apples in set_a
        for bananas in set_b
                sys = (system, limit=bananas)   # Define the system being studied 
                sim = Simulation(   # Establish the length and scenario of the simulation to run
                         ResidualModel, #Type of model used
                         sys,  # system
                         (0.0, 40.0), # time span
                         Disturbance(1.0, apples, :P, 0.9);
                         )
                 try
                         execute!(sim, IDA(); abstol = 1e-8)  # Command which runs the simulation 
                 catch 
                         break
                  else
                         continue
                  end
                  plot(read_results(sim))
             end
        end

However, this seems to break both loops since when I hit a condition I know will cause a convergence error (say 2.0 and 0.2 from above) the normal error message is displayed and the code stops advancing. Does anyone have any ideas on how to resolve this?

There are two forms of the for loop construct, see in the documentation and also here.

It seems for you that instead of:

for apples in set_a
    for bananas in set_b
      # stuff with maybe a break
    end
end

You might try:

for apples in set_a, bananas in set_b
    # stuff with maybe a break
end

For my purposes, the

for apples in set_a, bananas in set_b
# stuff
end

formulation would break both my loops, which was the opposite of what I was looking for. I only wanted to break out of set_b. Turned out the solution was to

try 
    read_results(sim)
catch err
    if isa(err, MethodError)
           break
   else 
           continue 
   end
end

because if the execute! command failed, it wouldn’t throw an error, but the results would be empty and that does throw an error.