How to continue the iteration when solve routes fail?

10-12-2017 02:01 PM
New Contributor II

Hi everyone,

I'm doing an iteration process to solve different shortest paths for different combinations of points. But the iteration stops when there is no solution for one combination. I think I may need if-else statement to check if solve fails, so I create a boolean variable "Terminate on solve error" to make it go through next step, but it still stuck at solve.

I'm new to python so don't know how to achieve this function. I attach the errors and part of the model in the screenshots. Does anyone have suggestions?


0 Kudos
3 Replies
Esri Regular Contributor

You mention python, but your screenshot shows Model Builder.  I'll try to answer this question for both.

In Model Builder, you can use that Solve Succeeded turquoise-colored bubble as a precondition for the next step in your workflow, I think.  If it's false, it should just skip whatever comes next.

In python, you can use try/except:


    print("Solve succeeded.")

    print("Solve failed.  Error messages:")


0 Kudos
New Contributor II

Hi Melinda,

Thank you for your help!

Yes I'm using the model builder and if it's possible, I want to achieve this without python. but if not, I'll try python code.

I just tried to use it as precondition of "Select Data" but the process still stuck at "Solve". It seems to me that the process is not able to go through "Solve" so that I can't use the parameter that "Solve" generates.

Can you tell me what should I do to insert this python code into this model? Shall I insert the python code by "Calculate Value"?

Thanks again!

0 Kudos
MVP Frequent Contributor

You can use 'CONTINUE' for parameter terminate_on_solve_error . For details:

0 Kudos