Any way to set an error message manually?

I am using a Try/Catch sequence in a flow. I would like to be able to set an error message manually when certain checks fail, and use getlastError() in the catch block.

Is there any way to manually set an error structure and then retrieve that information using getLastError()?

Write a Java service to accept a message and throw a ServiceException.

Thanks; will do :slight_smile:

you can also use exit step and use signal failure with the required message.

IME, the exit and signal failure does not always populate the right structures so that getLastErrorMessage returned the error. Thus, when I need to throw an exception I call a Java service that throws a ServiceException.

The PSUtilities package includes a Java service, throwError, that demonstrates how to throw a ServiceException as Rob explained. Here is a sample one that I have used before:
IDataCursor pipelineCursor = pipeline.getCursor();
String errorMessage = IDataUtil.getString( pipelineCursor, “errorMessage” );
String strErrorMessage = null;
if ( errorMessage != null ) {
strErrorMessage = errorMessage;
}
pipelineCursor.destroy();
throw new ServiceException(strErrorMessage)

Hi,

You can also use service WmPublic/pub.flow:throwExceptionForRetry and just give error message you want ti see in last error

Regards,
Yahya

In the try block, I just update a pipeline variable called (say), ‘someErrorVariable’, then exit the flow with failure.

In the catch block, after calling getLastError, I access the error variable in the pipeline in this manner:


  %lastError/pipeline/someErrorVariable%

This has worked well so far. Do the problems mentioned apply to this approach too?

Tried that, but even when I declared variables in the pipeline outside the try/catch block, I couldn’t access them from the catch block for some reason.

pipeline from try block is accessible in catch block under ‘lastError/pipeline’ as mentioned by sonam also …

Do you mean they don’t appear in the pipeline pane in Developer? Or that at runtime they are not present?