Invoking Workflow File's inside loops exception handling

Hi,

Say I have a workflow that looks like this:

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.

Hi Buddy @rmckinnon

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

you were almost done
Kindly try this and let know for any queries or clarification
Cheers @rmckinnon

I’m confused, because I am definitely getting an infinite loop bro.

In the Get Outlook Mail Messages, I clearly put to read only the first message.

I hit run, get a confirmation that I’ve obtained the OrderID from the first email:

image

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.

Thanks

@ClaytonM save me pls.

1 Like

:rofl:

You should not have the Main.xaml invoked in your Catch. This will cause an infinite loop potentially:
image

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:

  1. Initialize and Clean environment state to prevent application issues for process
  2. Process items (various ways to do this)
  3. a Try/Catch surrounding the Process section will catch any exceptions
  4. Log exception and take screenshot as desired
  5. Loop back to Process section for a retry attempt if desired
  6. Skip already completed items by using the current index
  7. 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.

Regards.

1 Like

Hi @rmckinnon

Please try this -

  1. Invoke “ControlMForceOK” within a try/catch block
  2. 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.

1 Like

@ClaytonM @goodoldme

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

image

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.

ControlMForceOK.xaml (51.4 KB) Main.xaml (24.6 KB)

2 Likes

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 :smile:

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.

Regards.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.