Send data from a try to a catch

Hello,
My flow service has the following structure:

global: Sequence (exit on SUCCESS)
        try: Sequence (exit on FAILURE)
        catch: Sequence (exit on DONE)

In the “catch” sequence, I need to know how I got there. Right now I want to declare a “flag” variable that I would change in the “try” sequence.
If I get to the “catch” sequence, I want to get the value of this “flag” so I can decide if I want to crash the service or not.

My problem is that I don’t know how to send data from the “try” to the “catch”: when I get to the catch I get the same pipeline I had at the beginning of the try sequence!

I can’t use “getLastError” because the error may have been already sent :frowning:
Do you have any solution?

Refer webM builtin services guide, where they provided some built in services for you to throw an error at runtime.

look at the usage of “pub.flow.throwExceptionForRetry” or write a simple java service where you can throw a ServiceException of an errorMessage

Define the variable that you want outside of the first sequence.

MAP (define the var)
SEQUENCE (exit on SUCCESS)
…SEQUENCE (try)
…SEQUENCE (catch)

Yup, it should work as Rob mentioned. Pardon me, I overlooked your question…

Hmm… there’s a variable called lastError/pipeline in the output of getLastError.

If my memory serves me correct, that’s how I have accessed a flag set in ‘try’ block… i.e. with the variable reference: %lastError/pipeline/myFlag%

If I define the variable outside of my global sequence, when I get to the catch it will be set to the value it had at the beginning of the TRY sequence, therefore any modification I make after that is useless.
I had forgotten that the pipeline was available in the lastError/pipeline, thank you!

The pipeline should be available.

HTH
Malhar

That hasn’t been my experience. Changes made to a “global” var are reflected in the catch block. I wonder if things have changed?

As mentioned by sonam, %lastError/pipeline/myFlag% should work.

I had a similar problem. The solution found was to use a document (structure) and place the variable inside the document. And, as it was already said, we initialized the variable before the Try sequence.

(Hope this helps someone, although the original post has more than a year already).

Yes, declaring the variable within a document and then setting it to a pre-defined value before the TRY block is a way of getting the changes performed to the value of the above variable (within TRY block) reflected in the CATCH block.