Try catch block exception handling

Hi,

In try catch block how many catch we can proceed?? Only one or multiple, if multiple means can you give some example to understand that in a easy way.

Hi @siva_sankar

You can use multiple catches based on scenario, A Try-Catch block can have multiple Catch blocks to handle different types of exceptions. Each Catch block is associated with a specific type of exception that it is designed to handle. When an exception occurs in the Try block, the corresponding Catch block is executed based on the type of exception thrown.

1 Like

Hi @siva_sankar

In a Try-Catch block in UiPath, you can have multiple Catch blocks to handle different types of exceptions. This allows you to write specific error-handling logic based on the type of exception that occurs. The Catch blocks are evaluated in order, and the first one that matches the type of the thrown exception is executed.

Here’s an example of a Try-Catch block with multiple Catch blocks in UiPath:

Try
    ' Your main workflow logic here

Catch ex As System.IO.IOException
    ' Handle IOException
    LogMessage("IOException occurred: " & ex.Message)

Catch ex As ArgumentException
    ' Handle ArgumentException
    LogMessage("ArgumentException occurred: " & ex.Message)

Catch ex As Exception
    ' Handle other types of exceptions
    LogMessage("An unexpected error occurred: " & ex.Message)

\\ You can log any exception if needed like BusinessRuleExceptions,System Exceptions aond many other.

End Try

It’s important to order the Catch blocks from the most specific to the most general exception types. If you have a more general Catch block at the top, it will catch all exceptions, and the subsequent Catch blocks won’t be executed.

Refer the below documentation for more understanding:

Follow these videos too:

Hope it helps!!
Regards