HowTo generate an Exception from Python/JYTHON than can be used with "Error Boundary Event"

I’d like to know which is the recommended method to generate an Exception from Python/Jython Script in a Script Task so it can be Used with Error Boundary Event + Event SubProcess

After reading Camunda Forum Messages

Handle ScriptEvaluationException with Error Boundary Event]
How can I get the Exception object when using a boundary error event?
Raise BPMN error from a user task as a boundary event
About 'Error Boundary Event' handle with sub process

I have tried

Option1

raise org.camunda.bpm.engine.delegate.BpmnError("ErrorCode1")

Option2

raise java.lang.Exception("ErrorCode1")

Option3

raise Exception("ErrorCode1")
Option1 Log Message

Option1 Log Message
05-Jul-2020 21:40:47.525 WARNING [http-nio-8080-exec-6] org.camunda.commons.logging.BaseLogger.logWarn ENGINE-REST-HTTP500 org.camunda.bpm.engine.rest.exception.RestException: Cannot complete task 22e72b02-bf08-11ea-b64e-0242ac130007: Unable to evaluate script while executing activity ‘T10’ in the process definition with id ‘a0P10:15:9f326e98-bf07-11ea-b64e-0242ac130007’: org.camunda.bpm.engine.delegate.BpmnError: org.camunda.bpm.engine.delegate.BpmnError: Este es el mensaje de ErrorCode1 Desde Jython Inline Script (errorCode=‘ErrorCode1’) in at line number 57

Option2 Log Message

Option2 Log Message
05-Jul-2020 22:12:44.637 SEVERE [http-nio-8080-exec-5] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 Exception while closing command context: Unable to evaluate script while executing activity ‘T10’ in the process definition with id ‘a0P10:18:8d975791-bf0c-11ea-b64e-0242ac130007’: java.lang.Exception: java.lang.Exception: ErrorCode1 in at line number 58

Option3 Log Message

Option3 Log Message
05-Jul-2020 22:08:49.763 SEVERE [http-nio-8080-exec-8] org.camunda.commons.logging.BaseLogger.logError ENGINE-16004 Exception while closing command context: Unable to evaluate script while executing activity ‘T10’ in the process definition with id ‘a0P10:17:0aa15740-bf0c-11ea-b64e-0242ac130007’: Exception: ErrorCode1 in at line number 57

WorkFlow Snapshot. Error Boundary Event.Properties Panel

WorkFlow Snapshot. Error Boundary Event.Properties Panel

WorkFlow Snapshot. Error Start Event.Properties Panel

WorkFlow Snapshot. Error Start Event.Properties Panel

1 Like

Hello,

I also need this.

I have been trying to access methods from Camunda BpmnError Class but i can´t find the way how to effectively “throw” the javascript BpmnError:

import org.camunda.bpm.engine.delegate.BpmnError as PythonException
import java.lang.Exception
my_error = PythonException('MYERROR')
my_error.initCause(my_error.getCause())

This doesn´t get detected by the event subprocess start therefore event subprocess (T2) in wf below never starts.

What is the correct procedure to throw the BpmnError in Jython?

1 Like

Thank you @jsomav. It’s good to know that there are more people facing the same problem.
Seen your config snippet , I realize i forgot to mention that I was already importing BpmnError Module

import org.camunda.bpm.engine.delegate.BpmnError

##########
Besides I was testing Java Methods/Functions from Jython Script and all of them worked perfectly

dir(bpmn_error)

dir(bpmn_error)=[‘class’, ‘copy’, ‘deepcopy’, ‘delattr’, ‘doc’, ‘ensure_finalizer’, ‘eq’, ‘format’, ‘getattribute’, ‘hash’, ‘init’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘str’, ‘subclasshook’, ‘unicode’, ‘addSuppressed’, ‘cause’, ‘class’, ‘equals’, ‘errorCode’, ‘fillInStackTrace’, ‘getCause’, ‘getClass’, ‘getErrorCode’, ‘getLocalizedMessage’, ‘getMessage’, ‘getStackTrace’, ‘getSuppressed’, ‘hashCode’, ‘initCause’, ‘localizedMessage’, ‘message’, ‘notify’, ‘notifyAll’, ‘printStackTrace’, ‘setStackTrace’, ‘stackTrace’, ‘suppressed’, ‘toString’, ‘wait’]

bpmn_error.getCause()=None
bpmn_error.getErrorCode()=ErrorCode1
bpmn_error.getMessage()=Este es el mensaje de ErrorCode1 Desde Jython Inline Script
bpmn_error.toString()=org.camunda.bpm.engine.delegate.BpmnError: Este es el mensaje de ErrorCode1 Desde Jython Inline Script (errorCode=‘ErrorCode1’)

Regards