How does finally block work in case of errors

Hi Everyone

I have developed a code where in we are connecting to application servers using sftp. Since we have to logout the sessions in case of success/failure, i have implemented the finally block.

Below is the flow:

MAIN[EXIT ON SUCCESS]
-TRY[EXIT ON FAILURE]
-CATCH[EXIT ON DONE]
FINALLY[EXIT ON DONE]

In the catch block, the last step is exit from parent and signal failure, so in case of failures, the finally block is unable to get the pipeline values, since at the exit step, the pipeline is being cleared.

Could someone please help me know how we can save the pipeline value(session names) in case of errors, so we can log out in finally block.

Thanks in advance.

Use logout as the last step in try block and after the getLastError in the catch block by doing this you don’t need a finally sequence.

Do you need finally block at any cost?

Thank you Mahesh for the reply.

In that case, we need to place logout service in try as well as in catch so during success, it will be implemented in try and in case of error, it will be implemented in Catch block.

To avoid repetition, i have placed finally block. So is there a way, we can fetch the pipeline data from catch lock too,after exit step is executed?

Of-course as per my design logout should be in try and catch if you do not want to use finally.

I hope you do not have any clear pipeline in the catch? Can you confirm. Let me try.

No, I do not have a clear pipeline in Catch block. The exit step is clearing the pipeline.

Please let me know if you need more information.

For me its as per the design if you specify exit from parent and signal failure, the pipeline data is cleared.

Use exit from parent and signal success to have the pipeline content so that you can logout in finally block.

Last option - use the design suggested by me, its just you are calling logout in try and catch. I have used in my project and it works like a charm.

Any questions?

For me its as per the design if you specify exit from parent and signal failure, the pipeline data is cleared.

Use exit from parent and signal success to have the pipeline content so that you can logout in finally block.

Last option - use the design suggested by me, its just you are calling logout in try and catch. I have used in my project and it works like a charm.

Any questions?

If i exit and signal it as success, i will not be able to monitor in MWS for failures, so i will use the logout step in both try and catch.

Thank you for the help :slight_smile:

Yes, I know :slight_smile:

But for now deal with it, lets see if someone suggests a better solution for your problem.

Is there any other work in the service after the main/finally sequences?

If not, it might be an option to exit from flow and signal failure.
This will cause the flow to exiting immediately.

exit from parent will only exit the main sequence and if there is an getLastError in the Implementation the failure message might be lost for monitoring if it is not handled properly.

I agree with Mahesh about the locations where to put the logout service calls.

Additionally, if your login is inside the try block the session key will not be available in the finally block.

Regards,
Holger