How to continue the Simulated annealing when Dynare stops?

I am doing estimation using Simulated Annealing. In every iteration, model would be simulated using Dynare with different set of parameters. But once it encounters a set of parameters which cannot satisfy the rank condition, Dynare stops and the whole simulation is stopped.
Is there a way I can skip this run, and continue the annealing program for next iteration?
I did try to put a ‘if’ after Dynare file. For example:

Dynare file_name
load file_name_results
if ~isfield(oo_.dr,‘ghx’)
objective = 10000000000000000;
…(carry on my program)

But it doesn’t work. Can anyone please let me know how can I solve this problem.
Thanks a lot.

Continue my post…
Or is there a code in Dynare to check the rank condition before it runs fully, so I can write a code to skip the set of parameters that cannot justify the rank condition and carry on the next iteration?

please…if anyone knows how to do…Really appreciate…

If you run Dynare in a loop, embed the Dynare call in a Matlab “try-catch”-statement.

Thank you soooooooooo much…It works.