Throw Exception into Exchange Scope

Hi everyone, I’m developing my automation using an “Exchange scope.” When I try to throw a business exception within the exchange scope, the exception doesn’t leave the exchange scope. This is unexpected behavior. Can anyone tell me if it’s due to the activity or a bug?
Does anyone have any suggestions for how to get the exception to go outside the exchange scope?

Thank you :slight_smile:

Can you elaborate abit more for us? Perhaps showing us some screenshots of this and what the behaviour is? Is the error completely ignored? Does it the execution continue to the activity after the scope?

The exception is caught by the Exchange scope, as if a try-catch were present.
Then execution continues with the activities after the Exchange scope.

Hi @simone.trenta ,

It seems that you are looking to stop the execution after business exception is caught, and I assume that you are writing this Exchange scope in another xaml which is child workflow call, if yes, then you need to introduce “Rethrow” activity to throw the exception in catch block which will be caught by parent workflow’s catch block and depending on the logic you have written the automation performs as required.

Try placing the Exchange Scope inside a Try-Catch block and rethrow the exception manually if caught. This is will help you see the exact exception.

Try
Exchange Scope
Catch ex
Log error
Throw New BusinessRuleException("Exchange failed: " + ex.Message)

Try this and let us know what exception you are getting.

My workflow is as follows


The exception I highlighted does not fall outside the exchange scope as I would have expected.

Well, in the catch block did you add “BusinessRuleException”?

The exception doesn’t exit the exchange scope as I would have expected.
There is NO try-catch block. The activity appears to have built-in try-catch-like behavior, but without the ability to catch the exception.

This is interesting, if possible, can you show us the workflow structure by collapsing the sequence and showing us on a high-level skeleton structure, this will help us to understand the flow.

Hi @simone.trenta

As per my knowledge, exchange scope does not propagate exceptions thrown inside it, including BusinessRuleException. Might be due to to its internal handling design, not a bug. To work around it, set a Boolean flag and message variable inside the scope, then use an If condition outside the scope to throw the exception. or wrapping the Exchange Scope in a Try-Catch block also helps catch unexpected failures.

If helpful, mark as solution. Happy automation with UiPath

Thanks for the screenshot, that helped.

Can you show us the logs, from a run and the properties pane from the scope, its acting as if ‘Continue on Exception’ is set to true.

Also have you considered using the modern integration service stuff rather than the exchange scope?

This is properties pane from the scope



There isn’t “Continue on Error” or “Continue on Exception” properties

And the logs?

Padding padding for min character count so I can post, ignore this sentence.

I don’t have logs, only the exception log and then it resumes execution as if the exception had not been thrown.

There are always logs when a robot runs, we need to see them.
Or upload a video of it executing, running step by step in debug mode.

I solved it by using only the activities that need to use email within the Exchange scope.
The other activities, including exception throwing, are no longer within the Exchange scope. I should re-run the previous scenario to get some logs. I’ll do that as soon as I can and post the logs here.