How to Use multiple try catch activity

Hi All,

Please assist me on below query,

I am using a try catch activity and within that in try am using two try catch simultaneously.

The issue am facing that, when am running a process if any exception found in 1st try catch the process stop and goes to main try catch and I want that if exception found in 1st try catch the process must go to 2nd try catch.

Any assistance on this will be help full.

Regards,
Saurav

1 Like

Can you share image of your workflow or try catch structure.

What do you do in the catch of the first try?

1 Like

Fine
welcome to uipath community
–whenever we are planning to use nested try catch make sure that the second try catch is used only in the CATCH block of first try catch like this
image

so when the process in the outer try block fails it will go to CATCH block of that try catch activty - which is now holding another try catch activity
–now we need to place the remedy sequence that is the one to be followed if any exception occurs, inside the TRY block of inner TRY CATCH activity
–again if that fails it will go to CATCH block of INNER TRY CATCH ACTIVITY

but keep in mind that these TWO TRY CATCH ACTIVITIES can manage exception till three stages only
–because when a sequence in first try block fails it will go to its catch block
–there we have another try block with sequence and if that fails it will go to its catch blk
–and if the sequence in that catch block fails it will come out of the whole outer try catch block

so usually to handle multiple exception we can split the exception types like business and application exception as we do in REFramework Which will eventually makes a retry in execution of the process,
for more details on how that looping is done when exception occurs, while creating a project in studio, choose REFramework template and it will show you the template to be used with those loops when exception occurs

hope this would help you
Cheers @SauravYadav

1 Like

Hi @Palaniyappan,

Thank you for sharing the detailed solution of my query.

Just to confirm one point here that total 3 try catch activity am using, and as you mentioned we require to keep the sequence as below,

1st try catch (In try block adding business sequence) and in Catch block of 1st try catch adding 2nd try catch activity.followed by exception sequence for 1st try catch.
2nd try catch (In try block addding business sequence) and in catch block of 2nd try catch adding 3rd try catch activity followed by exception sequence for 2nd try catch.
3rd try catch (In try block adding buisness sequence) and in catch block of 3rd try catch adding exception sequence of 3rd try catch.

And as you mentioned if I understood correctly you said in case of any exception the process go to catch sections of all try catch blocks.

But my question if in 1st try catch block no exception occured then the process will not move to catch section of 1st try catch block then in that case how the sequence of try block of 2nd & 3rd try catch block will execute.

Thanks in advance.

Regards,
Saurav

Perfect here the question is when to have try catch
And what to have in try catch
See usually in TRY CATCH is a exception handler and if any exception we feal like would occur along the process then we need to bound that sequence with Try block and it’s remedy action along the catch block and that is how try catch is been used in a programming standard right
So if try didn’t give any exception it will surely go to the next activity along the sequence and it should be made in such a way like catch should include activities only when any exception occurs
Or
We can do one thing if we want to continue with activities if no exception occurs in try block then we can place the next to go activities in FINAL block of try catch activity but keep in mind that final block will get executed regardless of error occurring or even not occuring
So better keep the sequence to continue with, next to TRY CATCH block when no error occurs

Hope this would help you
Cheers @SauravYadav

Hi @Palaniyappan,

Thank you for the detailed description, but to fix my issue I have taken another approach.

I have taken two try catch under one try catch (Main) and attached exception sequence under both inner try catch and in finally block for both inner try catch left blank, and added application close sequence in outer try catch (Main) under finally block.

This way I have handled my issue.

Regards,
Saurav