@JRubyMethod(name = "raise", optional = 3, frame = true, module = true, visibility = Visibility.PRIVATE, omit = true)
public static IRubyObject rbRaise(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
Ruby runtime = context.getRuntime();
// Check for a Java exception
ConcreteJavaProxy exception = null;
if (args.length == 0 && runtime.getGlobalVariables().get("$!") instanceof ConcreteJavaProxy) {
exception = (ConcreteJavaProxy)runtime.getGlobalVariables().get("$!");
} else if (args.length == 1 && args[0] instanceof ConcreteJavaProxy) {
exception = (ConcreteJavaProxy)args[0];
}
if (exception != null) {
// looks like someone's trying to raise a Java exception. Let them.
Object maybeThrowable = exception.getObject();
if (maybeThrowable instanceof Throwable) {
// yes, we're cheating here.
UnsafeFactory.getUnsafe().throwException((Throwable)maybeThrowable);
return recv; // not reached