Exception throw and rethrow

Can some one give me an example of business exception and system exception thrown from sub process and rethrown to parent process with try catch in main process and try catch in sub process please?

Do we throw System exceptions or only rethrow?

Thank you,

In the login workflow(subprocess), create a Try Catch activity. Inside the Try block, use an If condition String.IsNullOrEmpty(in_Username) and in the Then branch throw New BusinessRuleException("Username cannot be empty"). After the If, place a Click activity on the Login button. In the Catch block, first catch BusinessRuleException, log "SubProcess: Business exception - " + exception.Message and then use a Rethrow activity, then catch Exception, log "SubProcess: System exception - " + exception.Message and also use a Rethrow activity.

AND

In the main workflow, place a Try Catch activity. Inside the Try block, invoke the Login.xaml workflow and pass the argument in_Username. In the Catch block, add two exception handlers: first catch BusinessRuleException and log the message "Main: Business exception handled - " + exception.Message, then catch Exception and log the message "Main: System exception handled - " + exception.Message.

Cheers

1 Like

@A_Learner

Generally System exception occurs or gets raised by the compiler when some unhandled scenario occurs in our code but we can throw it as per demand as well using Throw activity with New SystemException("Sample System Exception")

Whereas business exception we intentionally throw as per business logic using Throw activity with New BusinessRuleException("Some data unavailable")

Sample Code:
TryCatchDemo.zip (51.9 KB)

Output:

2 Likes

It depends on your design

If the code is within try catch - Any exception in the code will be captured in the catch block. To pop this out - you need to add rethrow activity

Coming to your workflow files → You can either not keep the code within try catch block so that any exception will be captured in the Main Catch block

If you want to segregate exception and business exception even in workflow files - You can keep in try catch and use output arguments to know whether the status is success or not . Usually by keeping following arguments

bool_AE
bool_BE
strMessage

if all are success - both status will be false. Else True based on the exception

If segregation is not required - you can rethrow which is similar to not having try cath block only

1 Like

Thank you for the information shared, @sharazkm32 @ashokkarale @bhavesh.choubey

1 Like

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