Start page / Tutorials / Workflows / Workflow “Error”

Error handling in workflows

Modeling an error status

To model an error status, all you have to do is add a normal status to the model, go to the Status properties, and enable the “Error” type. The status is then shown with a red border in the model.

The error status must not be switched via a transition, i.e. it only has outgoing transitions just like the start status. These outgoing transitions are used to model error handling within the workflow.

If an error or exception occurs at any point in the workflow, the workflow instance is immediately set to the error status. The error status catches all exceptions that occur when running the workflow, even exceptions that are not handled in the workflow. After error handling, the workflow can be switched to the subsequent status (according to the workflow model).

Example: “Error” workflow

The “Error” workflow consists of the “errortest” workflow and the associated scripts “errorshow”, “errortest1”, and “errortest2”. The workflow is made available as a compressed zip file for import into the Template Store (“Workflows” node).

errortest1 script:

//!Beanshell
throw new IllegalArgumentException("Error test 1");

The first script, “errortest1”, throws an unhandled IllegalStateException. This exception is not handled in the workflow, but still results in the state being set to “Error” instead of “End”.

errortest2 script:

//!Beanshell
context.gotoErrorState("Error test 2", new IllegalArgumentException("Error test 2"));

The second script, “errortest2”, shows error handling within a script. The instance of the workflow is switched to the Error state as soon as an exception occurs using context.gotoErrorState(...) (also refer to FirstSpirit Access API, Interface task).

errorshow script:

import de.espirit.firstspirit.common.gui.*;
import de.espirit.firstspirit.access.*;
import de.espirit.firstspirit.ui.operations.RequestOperation;
import de.espirit.firstspirit.agency.OperationAgent;
 
errorInfo = context.getTask().getErrorInfo();
if (errorInfo != null) {
          text = new StringBuilder("<html>Error information:<br>");
          text.append("<ul>");
          text.append("<li>User: " + errorInfo.getUserLogin() + " (" + errorInfo.getUserName() + ")");
          text.append("<li>Comment: " + errorInfo.getComment());
          text.append("<li>Activity: " + errorInfo.getErrorActivity()); 
          text.append("<li>Error: " + errorInfo.getThrowable());
          text.append("<li>ErrorInfo: " + errorInfo.getErrorInfo());
          text.append("</ul>");
          text = text.toString();
          requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.addOk();
          requestOperation.perform(text);
                     
} else {
requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.perform("No error information is available.");
          }
context.doTransition("->Main");

The “errorshow” script displays error information via an error dialog. The dialog is called automatically via a workflow as part of error handling when an error occurs. The dialog contains relevant information for resolving errors (e.g. the user that started the workflow, the activity that resulted in the error, etc.):

The instance of the workflow is automatically reset to the “Main” state after the dialog has been displayed:

For information on error dialogs see Workflows / Messages and Plug-In Development / Message Boxes.

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.13 | Data privacy