How to handle catch block

Hi,

I have one workflow where I am adding many steps like click, type into, write line and many more. I want to apply exceptional handling in such a way that if any error ocurred while writing or clicking or something else then it should close the browser everytime.

I took this workflow in try block. In the catch block I pasted the code for closing browser and writing status in excel file. But the catch block is not executing. I have not used throw or rethrow.

Please suggest the solution. Thanks!

Have you added the correct exceptions in the catch-block?
Could you provide us with a screenshot?

@garima.sriv12

there is no need to add any throw or rethrow activities. When you are using catch block there we need to select excpetion type

when you see catch block there was default System.Exception added in that body when you gave any actions those will execute.

For your reference add any log messages in catch body so that you can get to know whether your flow is going to catch block or not.

for more idea on Try catch go throw below videos

If you find it helpful, mark it as solution to close this topic

Happy Automation!!

Hi @garima.sriv12

Pls try to - disable “Continue On Error” in activities wrap steps in Try-Catch, close browser and log error in Catch block, and use Throw or Global Exception Handler if needed.

If helpful, mark as solution. Happy automation with UiPath

@garima.sriv12,

I would suggest to use REFramework for this which will give you inbuilt logic to re initialize the browser in case of system exception.

REFramework would be the best practice while automating. Learn from here:

Pls check the exception you have selected in the catch block