public static Object unwrapRubyException(Object excObj) { // Unrescuable: // IRBreakJump, IRReturnJump, ThreadKill, RubyContinuation, MainExitException, etc. // These cannot be rescued -- only run ensure blocks if (excObj instanceof Unrescuable) { Helpers.throwException((Throwable)excObj); } // Ruby exceptions, errors, and other java exceptions. // These can be rescued -- run rescue blocks return (excObj instanceof RaiseException) ? ((RaiseException) excObj).getException() : excObj; }
/** * * Prints out an error message. * * @param exception An Exception thrown by JRuby */ private static void printException(Ruby runtime, Exception exception) { assert exception != null; if (exception instanceof RaiseException) runtime.printError(((RaiseException)exception).getException()); }
/** * * Prints out an error message. * * @param exception An Exception thrown by JRuby */ private static void printException(Ruby runtime, Exception exception) { if (exception instanceof RaiseException) runtime.printError(((RaiseException) exception).getException()); }
public static Object unwrapRubyException(Object excObj) { // Unrescuable: // IRBreakJump, IRReturnJump, ThreadKill, RubyContinuation, MainExitException, etc. // These cannot be rescued -- only run ensure blocks if (excObj instanceof Unrescuable) { Helpers.throwException((Throwable)excObj); } // Ruby exceptions, errors, and other java exceptions. // These can be rescued -- run rescue blocks return (excObj instanceof RaiseException) ? ((RaiseException) excObj).getException() : excObj; }
public void printError(Throwable t) { if (t instanceof RaiseException) { printError(((RaiseException) t).getException()); } PrintStream errorStream = getErrorStream(); try { t.printStackTrace(errorStream); } catch (Exception e) { t.printStackTrace(System.err); } }
@Deprecated public static void storeExceptionInErrorInfo(Throwable currentThrowable, ThreadContext context) { IRubyObject exception; if (currentThrowable instanceof RaiseException) { exception = ((RaiseException)currentThrowable).getException(); } else { exception = JavaUtil.convertJavaToUsableRubyObject(context.runtime, currentThrowable); } context.setErrorInfo(exception); }
@Deprecated public static void storeExceptionInErrorInfo(Throwable currentThrowable, ThreadContext context) { IRubyObject exception; if (currentThrowable instanceof RaiseException) { exception = ((RaiseException)currentThrowable).getException(); } else { exception = JavaUtil.convertJavaToUsableRubyObject(context.runtime, currentThrowable); } context.setErrorInfo(exception); }
@JRubyMethod public IRubyObject last_error(ThreadContext context) { RaiseException re = EncodingUtils.makeEconvException(context.runtime, ec); if (re != null) return re.getException(); return context.nil; }
@JRubyMethod(compat = RUBY1_9) public IRubyObject last_error(ThreadContext context) { RaiseException lastError = transcoder.getLastError(); if (lastError != null) return lastError.getException(); return context.nil; }
@JRubyMethod public IRubyObject last_error(ThreadContext context) { RaiseException re = EncodingUtils.makeEconvException(context.runtime, ec); if (re != null) return re.getException(); return context.nil; }
public static String getLocalJumpTypeOrRethrow(RaiseException re) { RubyException exception = re.getException(); Ruby runtime = exception.getRuntime(); if (runtime.getLocalJumpError().isInstance(exception)) { RubyLocalJumpError jumpError = (RubyLocalJumpError)re.getException(); IRubyObject reason = jumpError.reason(); return reason.asJavaString(); } throw re; }
private static IRubyObject raiseTimeoutError(ThreadContext context, RaiseException re) { Ruby runtime = context.runtime; return RubyKernel.raise( context, runtime.getKernel(), new IRubyObject[]{ runtime.getClassFromPath("Timeout::Error"), re.getException().callMethod(context, "message"), re.getException().callMethod(context, "backtrace")}, Block.NULL_BLOCK); } }
public static String getLocalJumpTypeOrRethrow(RaiseException re) { RubyException exception = re.getException(); Ruby runtime = exception.getRuntime(); if (runtime.getLocalJumpError().isInstance(exception)) { RubyLocalJumpError jumpError = (RubyLocalJumpError)re.getException(); IRubyObject reason = jumpError.reason(); return reason.asJavaString(); } throw re; }
private static IRubyObject raiseTimeoutError(ThreadContext context, RaiseException re) { Ruby runtime = context.runtime; return RubyKernel.raise( context, runtime.getKernel(), new IRubyObject[]{ runtime.getClassFromPath("Timeout::Error"), re.getException().callMethod(context, "message"), re.getException().callMethod(context, "backtrace")}, Block.NULL_BLOCK); } }
public static void storeNativeExceptionInErrorInfo(Throwable currentThrowable, ThreadContext context) { IRubyObject exception = null; if (currentThrowable instanceof RaiseException) { exception = ((RaiseException)currentThrowable).getException(); } else { Ruby runtime = context.runtime; // wrap Throwable in a NativeException object exception = new NativeException(runtime, runtime.getNativeException(), currentThrowable); ((NativeException)exception).prepareIntegratedBacktrace(context, currentThrowable.getStackTrace()); } context.setErrorInfo(exception); }
public static void storeNativeExceptionInErrorInfo(Throwable currentThrowable, ThreadContext context) { IRubyObject exception = null; if (currentThrowable instanceof RaiseException) { exception = ((RaiseException)currentThrowable).getException(); } else { Ruby runtime = context.runtime; // wrap Throwable in a NativeException object exception = new NativeException(runtime, runtime.getNativeException(), currentThrowable); ((NativeException)exception).prepareIntegratedBacktrace(context, currentThrowable.getStackTrace()); } context.setErrorInfo(exception); }
private IRubyObject fallback_cmp(ThreadContext context, IRubyObject other) { RubyArray res; try { res = (RubyArray) other.callMethod(context, "coerce", this); } catch (RaiseException ex) { if (ex.getException() instanceof RubyNoMethodError) return context.nil; throw ex; } return f_cmp(context, res.eltInternal(0), res.eltInternal(1)); }
public RaiseException newLoadError(String message, String path) { RaiseException loadError = newRaiseException(getLoadError(), message); loadError.getException().setInstanceVariable("@path", newString(path)); return loadError; }
public RaiseException newLoadError(String message, String path) { RaiseException loadError = newRaiseException(getLoadError(), message); loadError.getException().setInstanceVariable("@path", newString(path)); return loadError; }
public IRubyObject call() throws Exception { ThreadContext context = runtime.getCurrentContext(); try { return body.call(context); } catch (RaiseException re) { RubyKernel.puts(context, body.getBinding().getSelf(), new IRubyObject[] { RubyString.newString(runtime, "joroutine terminated with error: " + re.getMessage())}); RubyKernel.puts(context, body.getBinding().getSelf(), new IRubyObject[] {re.getException().backtrace()}); throw re; } }