diff --git a/core/src/main/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImpl.java b/core/src/main/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImpl.java index 0d5d4f58c..645373178 100644 --- a/core/src/main/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImpl.java +++ b/core/src/main/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImpl.java @@ -13,6 +13,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -108,6 +109,12 @@ Object executeWithParams(String qualifiedClassName, String methodName, Object... } + } catch (InvocationTargetException e) { + Throwable target = e.getTargetException(); + String errMsg = format("Java exec(): Invocation failed for method %s in class %s. Cause: %s", + methodName, qualifiedClassName, target); + LOGGER.error(errMsg, target); + throw new RuntimeException(errMsg, e); } catch (Exception e) { String errMsg = format("Java exec(): Invocation failed for method %s in class %s", methodName, qualifiedClassName); LOGGER.error(errMsg + ". Exception - " + e); diff --git a/core/src/test/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImplTest.java b/core/src/test/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImplTest.java index 2b971687f..16a09abfe 100644 --- a/core/src/test/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImplTest.java +++ b/core/src/test/java/org/jsmart/zerocode/core/engine/executor/javaapi/JavaMethodExecutorImplTest.java @@ -145,6 +145,7 @@ public void willPropagateExceptions() throws Exception { }); exception.printStackTrace(); assertThat(exception.getMessage(), containsString("Invocation failed for method squareRoot")); + assertThat(exception.getMessage(), containsString("Cause: java.lang.RuntimeException: Can not square root a negative number")); // The target exception is included in this exception (inside of the InvocationTargetException) assertThat(exception.getCause(), is(notNullValue())); assertThat(((InvocationTargetException)exception.getCause()).getTargetException().getMessage(),