@JRubyMethod(name = {"raise", "fail"}, optional = 3, module = true, visibility = PRIVATE, omit = true)
public static IRubyObject raise(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
// FIXME: Pass block down?
Ruby runtime = context.getRuntime();
RaiseException raise;
switch (args.length) {
case 0:
IRubyObject lastException = runtime.getGlobalVariables().get("$!");
if (lastException.isNil()) {
raise = new RaiseException(runtime, runtime.getRuntimeError(), "", false);
} else {
// non RubyException value is allowed to be assigned as $!.
raise = new RaiseException((RubyException) lastException);
}
break;
case 1:
if (args[0] instanceof RubyString) {
raise = new RaiseException((RubyException) runtime.getRuntimeError().newInstance(context, args, block));
} else {
raise = new RaiseException(convertToException(runtime, args[0], null));
}
break;
case 2:
raise = new RaiseException(convertToException(runtime, args[0], args[1]));
break;
default:
raise = new RaiseException(convertToException(runtime, args[0], args[1]), args[2]);
break;
}
if (runtime.getDebug().isTrue()) {
printExceptionSummary(context, runtime, raise.getException());
}
throw raise;
}