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()?
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)
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.