Exception handling exact way, is try catch mandatory for each workflow in process ? Requires to catch system exception?

Hi
When we say each re framework process needs exception handling can anyone explain what needs to done exactly ?

  1. For business exception i use throw and in catch rethrow…To get the BE msg in set transaction status for output report …
  2. Init has default sya exception handled
  3. Do we need to put each workflow in try catch n catch the system exception ?
1 Like

@1a2bc346dgjk7544ebjkkbvf

Ideally not…we need to use tey catch only when necessary like say ypu have some specific activities you need to do when exception occurs and then throw the error then use try catch to do that

Similarly if you have a need to do a different set of steps when exception occurs then use try catch and change flow accordingly

These are few examples

Cheers

1 Like

Hi @1a2bc346dgjk7544ebjkkbvf

Actually no need to use try catch for every workflow in RE Frameworks. RE Frameworks is already designed to handle the exceptions.

In any of the workflow in the the four states throws the error the RE Frameworks identify the error weather it is Business exception or System exception it will handle itself.

Let us consider there are two workflows, name it as Workflow1 and Workflow2.
The Workflow1 is in the process state, the workflow2 is invoking to workflow1. To throw the exceptions in workflow2 we have to encapsulate the workflow2 with try catch. Then If any exception is occured in Workflow2 the Rethrow activity which is in catch block throws exception to workflow1. Workflow1 is already in process state. Then REFrameworks will automatically handle the exception in Workflow1.

Remind this In RE Frameworks every state can handled the exceptions. It was designed mainly for retry mechanism, Transaction Iteration and Exception handling.

Hope it helps!!

1 Like

@Anil_G n @mkankatala

  1. So, one should only throw BE right ? Rather rethrow from inner catch to outer catch …With proper message …Is my understanding correct now ??

2.all SE framework will take care no need to handle them unless required.

  1. Can I use throw BE 2 ,3times in same workflow ? And catch only once ? By giving log msg . +Exception.msg
    And rethrow only once ?
    … so that that exception msg will come till set transaction status.

Yes don’t need to use try catch until unless required. If you know at anywhere the business exception is required you have to use throw.

You can use the throw activity 2 or 3 times if required in the workflow, based on the exception. If it is System exception it will trigger to system exception sequence in set transaction status and it will go from process state to Initialization state, If it is Business exception it will trigger to business Exception sequence in set transaction status then it will go from process state to Get transaction state.

Hope you understand!! @1a2bc346dgjk7544ebjkkbvf

1 Like

@1a2bc346dgjk7544ebjkkbvf I hope you understand. If you are satisfied with the solution. Make mark it as solution to close the loop.

Happy Automation!!

1 Like

@1a2bc346dgjk7544ebjkkbvf

Try catch is not only for business exception…and throw also is not only for BE

For instance you have a web page and you are navigating to a page…then we can check for page transition and if the new page is kot loaded we can throw a system exception in that case…

Two ways to handle it is…one to check for element and throw using element exists or check apps tate…other way is to use a try catch around the next activity that happens on the target page and throw an exception in the catch block…

Both ways are legit. Where one is proactive and other is reactive…

Similarly…when we want to give any custom messaging instead of the same exception that UiPath throws…for example…object ref nit set to an instance of object is a generic message we get when null variable is present…instead of let it go to the top layer…we can use a try catch where we feel this might occur and catch the nullrefexception anf throw with a different user friendly message …even for that we can use a try catch inside instead of the ones that are available at the top layer

Hope this helps

Cheers

Cheers

1 Like

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