How to achieve "Exit and Signal Failure" behavior in a Java Service.

Hey guys,
Been reading similar posts on the forum here and gave em all a try but looks like I am still missing something. I have spent a lot of time on this on my own and now I think I need some help trying to figure out this problem.

Here is the setup:

Flow Service A:
Try Block: Calls Flow Service B
Catch Block: Handle Error. (This is a custom java service I wrote on the same lines of getLastError. I did this because I wanted to extend the behavior of getLastError.)
Flow Service B: (No Try/Catch in this one)
Call Service C
Do some transformation
Flow Service C:
Try Block: Does a bunch of transformations
Catch Block: Handle Error (same custom java service instead of getLastError)
Exit and Signal Failure.

This setup works perfectly. When there is an error in Service C, the error bubbles up to Service A’s catch block and by inspecting the pipeline object in the lastError doc, I am able to get the error that happened in service C and do whatever I need to do there.

What am I trying to do?:
I want to combine the Handle Error service and the Exit and Signal Failure steps into one Java service and have a service like Handle Error and re-throw. When I throw a ServiceException from within the Java Service, the control is not being handled to the Catch Block of Flow Service A.

Attached is the code to my custom getLastError. Sorry for the long post, wanted to be as clear as possible.

Thanks in adavance,
getLastError_Custom.txt (2.2 KB)

Is the catch block of C set to be “Exit on Done?” If so, I think that’s why the exception thrown by the custom getLastError isn’t being propagated up.

Yes. It’s set to exit on Done. But, why does the error propagate up when I use the Exit $flow and Signal Failure step?

One thing I found is that I can only throw a ServiceException in my java service and when I use a Exit step, it throws a FlowException. Could this be why? Anyone know how to throw a FlowException? I tried creating a java service to do this - but since the signature of a java service is by default “throws ServiceException”, I can’t throw a FlowException as it is not a subclass of ServieException.

…I think this can’t be done. You agree?


Is the exit flow and signal failure inside the catch block?

What I typically do is set a flag in the catch block. Then outside the catch block I check the flag and throw the exception.

Yes, the exit is inside the catch block. I thought about the approach you mentioned, but, I want to see if this works.

Change the catch block to exit on error.