In this workflow, I am parsing through emails, getting a specific ID, then send this information over to the invoked workflow “ControlMForceOK”
In this invoked workflow, my automation would continue. However, my problem is how I should be dealing with exceptions.
For example, in my automation I search for something in my application, but if this cannot be found, I want to catch this exception, stop the process, and revert back to the loop from the first screenshot in the same position that it was left in as if the automation did the full process.
How can I do this? I am looking for logic like a “Continue” statement, only the Continue activity won’t actually work here because it is not in a for loop. In this screenshot you can see I tried invoking the “Main” workflow which is the workflow that contains that loop from the first screenshot. This will not work and actually results in an infinite loop.
My other idea is to just shove everything in my ControlM workflow within the first loop, but I really would like to not do that.
This one looks good, fine in getting the value and storing them to the variable
They way you handled is correct, Yes
how…?
Here is the answer , this wont lead to infinite loop the reason is,
CATCH block will get executed only when an exception occurs in try block,
–Still use a log message activity with a log message like exception.Message next to the main workflow mentioned in the catch workflow, and this is done even if any exception still occurs even in the repeating process workflow mentioned in the catch block, It will not get to infinite loop buddy
I hit run, get a confirmation that I’ve obtained the OrderID from the first email:
My automation continues as expected, opening an application called ControlM up and I set up a message box to confirm I read the status correctly. In this case the Status doesn’t = the keyword I’m looking for so my exception is to catch this and break out of this iteration.
(The exception is the exact same screenshot that you reposted)
So, I would expect the automation to return to original loop, and go: the first email has been parsed so now the loop is done
But what happens is the automation continues onto the next email, the exact same email actually. And just keeps infinite looping. I don’t want this. How can i fix this? @Palaniyappan
Hope that’s more clear, I could really use some help I’m so confused.
You should not have the Main.xaml invoked in your Catch. This will cause an infinite loop potentially:
Additionally, I think I would need to know more of your workflow, like are you using some Framework (ie REF), where it calls the Process state/sequence, catches exceptions, then loops back around for a retry attempt, and when no exceptions occured, then enter the End/Closure state/sequence.
So best practice to manage exceptions is as follows:
Initialize and Clean environment state to prevent application issues for process
Process items (various ways to do this)
a Try/Catch surrounding the Process section will catch any exceptions
Log exception and take screenshot as desired
Loop back to Process section for a retry attempt if desired
Skip already completed items by using the current index
Exit to End sequence when Process is complete with no errors
That’s just a simple explanation, but can be more complicated than that to get all the robustness you are looking for.
Going back to your question. I think problem is that you are Invoking the Main.xaml in the Catch. I would also need to see the rest of your workflow files so I know how you are exiting the Process section where your ForEach is at.
You have two options:
a) Have a separate try/catch block within “ControlMForceOK” to catch any exceptions and then rethrow/throw a new exception from there. The thrown exception will then be caught by the try/catch surrrounding the invoke (#1)
b) Do not handle the exception within Main.xaml and let it be caught by the catch surrounding invoke of ControlMForceOK (#1)
The execution will be back to where it started. Hope this helps.
Just an update of what I ended up doing. It seems to work so far, In my Main.xaml which read emails then goes to the ControlM workflow, I put a try catch block then continue
Then through out the ControlM workflow in my exception handling I put the “rethrow” activity and it seems to do the job.
While I think this is going to work for me, do you see any downsides of using this method or shortcomings I’m missing? Thanks for the help!
You won’t be able to run them but here are my workflows.
Hi. Just clarifying some use-cases for the Continue and Rethrow that I believe may help you understand it better.
Whenever you have a condition in a loop where you want it to end the current ForEach iteration and go to next item in the loop, then Continue can be useful. However, if your loop is only one item, then it’s kind of pointless and there could be other coding flaws causing it to not end the loop. But, if it works, it works
Whenever you need to perform a few actions from an error before exiting to error handling, then the Rethrow or Throw activity can be used to send it up a layer to the outer Catch for error handling. And, Rethrow will use the exception that had been thrown, whereas Throw you can customize your message (ie “Password expired”). Typically, Rethrow is useful to troubleshoot errors inside a Try/Catch, but the way you are using it is perfectly fine too, to click a few buttons, then exit to the outer layer Catch for error handling.