What is best practices to retry a sequence of activities only if a system exception was thrown?

Hello everyone,

I am sorry if this issue has already been discussed, explained or solved in the past. I could not find anything since all results that appear are in regards to the REFramework that contains this logic.

This does not apply to my issue, as I’m handling a sequence that is not a transaction.

The result that I want to achieve is the following:
A sequence of activities is executed. When in that sequence an exception occurs, I want to handle it to retry the logic if a System Exception occurred, and not retry the logic if a Business Exception occurred.

The two possible solutions I was thinking about are the following:

  1. I can place the sequence of activities in a try / catch. I can catch two different types of exceptions: BusinessRuleException and Exception. In the handling of the type ‘Exception’ I can add a rethrow activity. I will place the entire try / catch scope in a retry activity.
  2. I can place the entire sequence in a try / catch that only catches BusinessRuleExceptions. Then, I can place that try / catch scope in a retry scope. If a System Exception was thrown, it will not be caught by the try/catch, as it only catches BREs. Then I can place the retry scope in another try catch, that will catch exceptions of type ‘Exception’.

What solution is better? Solution 1 seems like a cleaner / better solution to me, but I have never used rethrow before, and all the examples I see of it being used are of a “lower lever workflow” and a “higher level workflow”. As you can see, I don’t have that.

On the other hand, solution 2 makes sense and I know it will work, but doesn’t seem like “best practices” to me.

If neither solution applies to best practices, please let me know of other better solutions I haven’t thought of.

Also, before anyone suggests it, I am actually using a REFramerwork. However, there is a small subsection of the process that requires to be handled separately (as described above) due to some requirements.

Thank you in advance for your answers!

@M_Kr

There is an advantage of the first approach …that is you can log the exception message from the main flow as well…and then rethrow to retry the flow again…

Contrary in the second approach you will not know the exception that has occured in the flow as the error theow will be max retry reached when retry fails for maximum times…

Cheers

That is also true, I hadn’t considered that. If no one suggests a better approach, that is the approach that I will go with.

1 Like