[Java] Add java exception check in JNI (#6378)

This commit is contained in:
Kai Yang
2019-12-07 16:25:17 +08:00
committed by Hao Chen
parent e2ba8c1898
commit 7e9fddf3ed
5 changed files with 79 additions and 8 deletions
@@ -0,0 +1,19 @@
package org.ray.runtime.util;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Required by JNI macro RAY_CHECK_JAVA_EXCEPTION
public final class JniExceptionUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(JniExceptionUtil.class);
public static String getStackTrace(String fileName, int lineNumber, String function,
Throwable throwable) {
LOGGER.error("An unexpected exception occurred while executing Java code from JNI ({}:{} {}).",
fileName, lineNumber, function, throwable);
// Return the exception in string form to JNI.
return ExceptionUtils.getStackTrace(throwable);
}
}