Try catch finally
Application Type
Traditional Web, Service

Does OutSystems has the Finally clause in the Try Catch flow?

Basically, I do not want the code to end abruptly, I want it to continue to the end even if exceptions are caught along the way.

I checked a few posts but cannot find what I need.


mvp_badge
MVP

Hi WeiWei,


There are two ways for you to continue the transaction without rollbacking.

In both of them you need to handle exceptions inside your actions.

You can either use CommitTransaction from System before the action throws an exception.

 

Or you can set the Exception Handlers to have the property Abort Transaction set to No.


Given that you're "overriding" the default behavior, I would prefer option 1 as it becomes more visible and explicit (and therefore better to maintain and to be understood by other developers) rather than the option not to abort on the exception handling.


Kind Regards,
João

Are you stating that I should use commit transaction before exception is raised? 


If so, how can I get the exception to raise and still have the flow continues? Would option 2 works in this case? 

mvp_badge
MVP

Your logic flow should be composed by actions and these actions should have an exception handler, like this:


Your main action, composed of other actions, should use CommitTransaction, like this:


Kind Regards,
João

Regarding handling exception, when it comes to best practice, is it better for me to have each server action handling it's own exception or I should get the main one to handle?

Scenario 1:

SendKidToSchool main server action. It calls 2 server actions DriveToSchool and RouteA. Both of these server actions are only used by SendKidToSchool.

Scenario 2:

CheckTrafficCondition server action is a common one shared by SendKidToSchool, GoToAirport, GoShopping.


Currently, 

For Scenario 1, I have removed all exception handling in both DriveToSchool and RouteA server actions so that it can be handled by SendKidToSchool

For Scenario 2, I have exception handling inside of CheckTrafficCondition for specific exception, and have the "CatchAll" handled by the caller server action.


Is this a correct approach? If not, I am all ears :)

Yes Joao, your screenshot and explanation is clear. Thank you. I will test it out and reply when I need more help. 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.