protected void setException(RubyException newException,
boolean nativeException) {
Ruby runtime = newException.getRuntime();
ThreadContext context = runtime.getCurrentContext();
if (!context.isWithinDefined()) {
runtime.getGlobalVariables().set("$!", newException);
}
if (runtime.hasEventHooks()) {
runtime.callEventHooks(
context,
RubyEvent.RAISE,
context.getFile(),
context.getLine(),
context.getFrameName(),
context.getFrameKlazz());
}
this.exception = newException;
if (runtime.getStackTraces() > 5) {
return;
}
runtime.setStackTraces(runtime.getStackTraces() + 1);
StackTraceElement[] stackTrace = context.createBacktrace2(0, nativeException);
newException.setBacktraceFrames(stackTrace);
// JRUBY-2673: if wrapping a NativeException, use the actual Java exception's trace as our Java trace
if (newException instanceof NativeException) {
setStackTrace(((NativeException)newException).getCause().getStackTrace());
} else {
setStackTrace(stackTrace);
}
runtime.setStackTraces(runtime.getStackTraces() - 1);
}
|