@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { if (recv == runtime.getException() || object instanceof java.lang.Exception) { return context.tru; } } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { if (recv == runtime.getException() || object instanceof java.lang.Exception) { return context.tru; } } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { return context.runtime.getTrue(); } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
@JRubyMethod(name = "===", meta = true) public static IRubyObject op_eqq(ThreadContext context, IRubyObject recv, IRubyObject other) { Ruby runtime = context.runtime; // special case non-FlowControlException Java exceptions so they'll be caught by rescue Exception if (other instanceof ConcreteJavaProxy && (recv == runtime.getException() || recv == runtime.getStandardError())) { Object object = ((ConcreteJavaProxy)other).getObject(); if (object instanceof Throwable && !(object instanceof FlowControlException)) { return context.runtime.getTrue(); } } // fall back on default logic return ((RubyClass)recv).op_eqq(context, other); }
@Override @JRubyMethod(name = "==") public RubyBoolean op_equal(ThreadContext context, IRubyObject other) { if (this == other) return context.tru; boolean equal = context.runtime.getException().isInstance(other) && getMetaClass().getRealClass() == other.getMetaClass().getRealClass() && callMethod(context, "message").equals(other.callMethod(context, "message")) && callMethod(context, "backtrace").equals(other.callMethod(context, "backtrace")); return context.runtime.newBoolean(equal); }
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule timeout = runtime.defineModule("Timeout"); RubyClass superclass = runtime.is1_9() ? runtime.getRuntimeError() : runtime.getInterrupt(); RubyClass timeoutError = runtime.defineClassUnder("Error", superclass, superclass.getAllocator(), timeout); runtime.defineClassUnder("ExitException", runtime.getException(), runtime.getException().getAllocator(), timeout); // Here we create an "anonymous" exception type used for unrolling the stack. // MRI creates a new one for *every call* to timeout, which can be costly. // We opt to use a single exception type for all cases to avoid this overhead. RubyClass anonEx = runtime.defineClassUnder("AnonymousException", runtime.getException(), runtime.getException().getAllocator(), timeout); anonEx.setBaseName(null); // clear basename so it's anonymous when raising // These are not really used by timeout, but exposed for compatibility timeout.defineConstant("THIS_FILE", RubyRegexp.newRegexp(runtime, "timeout\\.rb", new RegexpOptions())); timeout.defineConstant("CALLER_OFFSET", RubyFixnum.newFixnum(runtime, 0)); // Timeout module methods timeout.defineAnnotatedMethods(Timeout.class); // Toplevel defines runtime.getObject().defineConstant("TimeoutError", timeoutError); runtime.getObject().defineAnnotatedMethods(TimeoutToplevel.class); }
@Override @JRubyMethod(name = "==") public RubyBoolean op_equal(ThreadContext context, IRubyObject other) { if (this == other) return context.tru; boolean equal = context.runtime.getException().isInstance(other) && getMetaClass().getRealClass() == other.getMetaClass().getRealClass() && callMethod(context, "message").equals(other.callMethod(context, "message")) && callMethod(context, "backtrace").equals(other.callMethod(context, "backtrace")); return context.runtime.newBoolean(equal); }
public void load(Ruby runtime, boolean wrap) throws IOException { RubyModule timeout = runtime.defineModule("Timeout"); RubyClass superclass = runtime.is1_9() ? runtime.getRuntimeError() : runtime.getInterrupt(); RubyClass timeoutError = runtime.defineClassUnder("Error", superclass, superclass.getAllocator(), timeout); runtime.defineClassUnder("ExitException", runtime.getException(), runtime.getException().getAllocator(), timeout); // Here we create an "anonymous" exception type used for unrolling the stack. // MRI creates a new one for *every call* to timeout, which can be costly. // We opt to use a single exception type for all cases to avoid this overhead. RubyClass anonEx = runtime.defineClassUnder("AnonymousException", runtime.getException(), runtime.getException().getAllocator(), timeout); anonEx.setBaseName(null); // clear basename so it's anonymous when raising // These are not really used by timeout, but exposed for compatibility timeout.defineConstant("THIS_FILE", RubyRegexp.newRegexp(runtime, "timeout\\.rb", new RegexpOptions())); timeout.defineConstant("CALLER_OFFSET", RubyFixnum.newFixnum(runtime, 0)); // Timeout module methods timeout.defineAnnotatedMethods(Timeout.class); // Toplevel defines runtime.getObject().defineConstant("TimeoutError", timeoutError); runtime.getObject().defineAnnotatedMethods(TimeoutToplevel.class); }
@Override public IRubyObject set(IRubyObject value) { if (!value.isNil() && !runtime.getException().isInstance(value) && !(JavaUtil.isJavaObject(value) && JavaUtil.unwrapJavaObject(value) instanceof Throwable)) { throw runtime.newTypeError("assigning non-exception to $!"); } return runtime.getCurrentContext().setErrorInfo(value); }
@Override public IRubyObject set(IRubyObject value) { if (!value.isNil() && !runtime.getException().isInstance(value) && !(JavaUtil.isJavaObject(value) && JavaUtil.unwrapJavaObject(value) instanceof Throwable)) { throw runtime.newTypeError("assigning non-exception to $!"); } return runtime.getCurrentContext().setErrorInfo(value); }
@JRubyMethod(name = "==", compat = CompatVersion.RUBY1_9) @Override public IRubyObject op_equal(ThreadContext context, IRubyObject other) { if (this == other) return context.runtime.getTrue(); boolean equal = context.runtime.getException().isInstance(other) && callMethod(context, "message").equals(other.callMethod(context, "message")) && callMethod(context, "backtrace").equals(other.callMethod(context, "backtrace")); if (context.runtime.is2_0()) { equal = equal && getMetaClass().getRealClass() == other.getMetaClass().getRealClass(); } return context.runtime.newBoolean(equal); }
@Override public IRubyObject set(IRubyObject value) { if (!value.isNil() && !runtime.getException().isInstance(value) && !(JavaUtil.isJavaObject(value) && JavaUtil.unwrapJavaObject(value) instanceof Throwable)) { throw runtime.newTypeError("assigning non-exception to $!"); } return runtime.getCurrentContext().setErrorInfo(value); }
@Override public IRubyObject set(IRubyObject value) { if (!value.isNil() && !runtime.getException().isInstance(value) && !(JavaUtil.isJavaObject(value) && JavaUtil.unwrapJavaObject(value) instanceof Throwable)) { throw runtime.newTypeError("assigning non-exception to $!"); } return runtime.getCurrentContext().setErrorInfo(value); }
@JRubyMethod(name = "==", compat = CompatVersion.RUBY1_9) @Override public IRubyObject op_equal(ThreadContext context, IRubyObject other) { if (this == other) return context.runtime.getTrue(); boolean equal = context.runtime.getException().isInstance(other) && callMethod(context, "message").equals(other.callMethod(context, "message")) && callMethod(context, "backtrace").equals(other.callMethod(context, "backtrace")); if (context.runtime.is2_0()) { equal = equal && getMetaClass().getRealClass() == other.getMetaClass().getRealClass(); } return context.runtime.newBoolean(equal); }
private boolean exceptionHandled(ThreadContext context, IRubyObject excType, Object excObj) { Ruby runtime = context.runtime; if (excObj instanceof IRubyObject) { // regular ruby exception if (!(excType instanceof RubyModule)) throw runtime.newTypeError("class or module required for rescue clause. Found: " + excType); return excType.callMethod(context, "===", (IRubyObject)excObj).isTrue(); } else if (runtime.getException().op_ge(excType).isTrue() || runtime.getObject() == excType) { // convert java obj to a ruby object and try again return excType.callMethod(context, "===", JavaUtil.convertJavaToUsableRubyObject(runtime, excObj)).isTrue(); } else if (excType instanceof RubyClass && excType.getInstanceVariables().hasInstanceVariable("@java_class")) { // java exception where the rescue clause has an embedded java class that could catch it RubyClass rubyClass = (RubyClass)excType; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(excObj)) return true; } } return false; }
private boolean exceptionHandled(ThreadContext context, IRubyObject excType, Object excObj) { Ruby runtime = context.runtime; if (excObj instanceof IRubyObject) { // regular ruby exception if (!(excType instanceof RubyModule)) throw runtime.newTypeError("class or module required for rescue clause. Found: " + excType); return excType.callMethod(context, "===", (IRubyObject)excObj).isTrue(); } else if (runtime.getException().op_ge(excType).isTrue() || runtime.getObject() == excType) { // convert java obj to a ruby object and try again return excType.callMethod(context, "===", JavaUtil.convertJavaToUsableRubyObject(runtime, excObj)).isTrue(); } else if (excType instanceof RubyClass && excType.getInstanceVariables().hasInstanceVariable("@java_class")) { // java exception where the rescue clause has an embedded java class that could catch it RubyClass rubyClass = (RubyClass)excType; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(excObj)) return true; } } return false; }
private static boolean checkJavaException(Throwable throwable, IRubyObject catchable, ThreadContext context) { Ruby runtime = context.runtime; if ( // rescue exception needs to catch Java exceptions runtime.getException() == catchable || // rescue Object needs to catch Java exceptions runtime.getObject() == catchable || // rescue StandardError needs t= catch Java exceptions runtime.getStandardError() == catchable) { if (throwable instanceof RaiseException) { return isExceptionHandled(((RaiseException)throwable).getException(), catchable, context).isTrue(); } // let Ruby exceptions decide if they handle it return isExceptionHandled(JavaUtil.convertJavaToUsableRubyObject(runtime, throwable), catchable, context).isTrue(); } else if (runtime.getNativeException() == catchable) { // NativeException catches Java exceptions, lazily creating the wrapper return true; } else if (catchable instanceof RubyClass && catchable.getInstanceVariables().hasInstanceVariable("@java_class")) { RubyClass rubyClass = (RubyClass)catchable; JavaClass javaClass = (JavaClass)rubyClass.getInstanceVariable("@java_class"); if (javaClass != null) { Class cls = javaClass.javaClass(); if (cls.isInstance(throwable)) { return true; } } } return false; }
if ( runtime.getException() == catchable ||
if ( runtime.getException() == catchable ||
if (!runtime.getException().isInstance(exception)) { return runtime.newTypeError("exception object expected").getException();