Capture multiple Business Rule Exception with Try Catch

Hello, dear community.

Today, I’m here to ask a question that I’ve been pondering for a while now.

The situation is as follows: I have a complete workflow surrounded by a try-catch. Inside this workflow, there’s a process with multiple possible Business Rules Exceptions. I want to capture every business exception, but I also need to execute a different flow in the catch block for each specific business exception. How can I handle this scenario? Is it possible to create different catch blocks for different business exceptions? I know it’s not, but perhaps I can use other similar types of exceptions?

One idea I had is to use a “Switch” activity within the catch block for business exceptions. This switch would examine the message property that I would assign for each Business Rule Exception I throw in my workflow. Each message would have to be unique for each business exception I throw.

However, I’m wondering if there’s a better way to handle these kinds of scenarios. Any feedback is welcome.

Thank you in advance for your attention.

Regards Luis Fernando Pazos, The Fisrt Venezuelan RPA Developer :grin:

A Switch is the appropriate way to handle it. Depending upon the complexity, you could also use a Flowchart inside the Catch block.

1 Like

Hi @Luis_Fernando

Try this way:

Try: 
    Throw -->New BusinessRuleException("Exception 1")
    Throw -->New BusinessRuleException("Exception 2")
Catch:
    Switch(exception.message):
        case - 1: Exception 1
            Log the exception message
        case - 2: Exception 2
            Log the exception message
1 Like

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