本文整理了Java中org.jruby.Ruby.getException
方法的一些代码示例,展示了Ruby.getException
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ruby.getException
方法的具体详情如下:
包路径:org.jruby.Ruby
类名称:Ruby
方法名:getException
[英]Get the current exception count.
[中]获取当前异常计数。
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-core
@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);
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@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);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
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);
}
代码示例来源:origin: org.jruby/jruby-core
@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);
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
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);
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@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);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@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);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
@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);
}
代码示例来源:origin: org.jruby/jruby-complete
@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);
}
代码示例来源:origin: org.jruby/jruby-core
@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);
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
@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);
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
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;
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
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;
}
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
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;
}
代码示例来源:origin: org.jruby/jruby-core
if (
runtime.getException() == catchable ||
代码示例来源:origin: org.jruby/jruby-complete
if (
runtime.getException() == catchable ||
代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby
if (!runtime.getException().isInstance(exception)) {
return runtime.newTypeError("exception object expected").getException();
内容来源于网络,如有侵权,请联系作者删除!