use of org.camunda.bpm.engine.impl.bpmn.parser.ErrorEventDefinition in project camunda-bpm-platform by camunda.
the class AbstractBpmnActivityBehavior method propagateError.
protected void propagateError(String errorCode, String errorMessage, Exception origException, ActivityExecution execution) throws Exception {
ActivityExecutionHierarchyWalker walker = new ActivityExecutionHierarchyWalker(execution);
final ErrorDeclarationForProcessInstanceFinder errorDeclarationFinder = new ErrorDeclarationForProcessInstanceFinder(origException, errorCode, execution.getActivity());
ActivityExecutionMappingCollector activityExecutionMappingCollector = new ActivityExecutionMappingCollector(execution);
walker.addScopePreVisitor(errorDeclarationFinder);
walker.addExecutionPreVisitor(activityExecutionMappingCollector);
// map variables to super executions in the hierarchy of called process instances
walker.addExecutionPreVisitor(new OutputVariablesPropagator());
try {
walker.walkUntil(new ReferenceWalker.WalkCondition<ActivityExecutionTuple>() {
@Override
public boolean isFulfilled(ActivityExecutionTuple element) {
return errorDeclarationFinder.getErrorEventDefinition() != null || element == null;
}
});
} catch (Exception e) {
// separate the exception handling to support a fail-safe error propagation
throw new ErrorPropagationException(e);
}
PvmActivity errorHandlingActivity = errorDeclarationFinder.getErrorHandlerActivity();
// process the error
if (errorHandlingActivity == null) {
if (origException == null) {
if (Context.getCommandContext().getProcessEngineConfiguration().isEnableExceptionsAfterUnhandledBpmnError()) {
throw LOG.missingBoundaryCatchEventError(execution.getActivity().getId(), errorCode);
} else {
LOG.missingBoundaryCatchEvent(execution.getActivity().getId(), errorCode);
execution.end(true);
}
} else {
// throw original exception
throw origException;
}
} else {
ErrorEventDefinition errorDefinition = errorDeclarationFinder.getErrorEventDefinition();
PvmExecutionImpl errorHandlingExecution = activityExecutionMappingCollector.getExecutionForScope(errorHandlingActivity.getEventScope());
if (errorDefinition.getErrorCodeVariable() != null) {
errorHandlingExecution.setVariable(errorDefinition.getErrorCodeVariable(), errorCode);
}
if (errorDefinition.getErrorMessageVariable() != null) {
errorHandlingExecution.setVariable(errorDefinition.getErrorMessageVariable(), errorMessage);
}
errorHandlingExecution.executeActivity(errorHandlingActivity);
}
}
Aggregations