Ruby runtime = context.getRuntime();
if (args.length == 0) {
IRubyObject lastException = runtime.getGlobalVariables().get("$!");
if (lastException.isNil()) {
throw new RaiseException(runtime, runtime.getRuntimeError(), "", false);
}
throw new RaiseException((RubyException) lastException);
}
IRubyObject exception;
if (args.length == 1) {
if (args[0] instanceof RubyString) {
throw new RaiseException((RubyException)runtime.getRuntimeError().newInstance(context, args, block));
}
if (!args[0].respondsTo("exception")) {
throw runtime.newTypeError("exception class/object expected");
}
exception = args[0].callMethod(context, "exception");
} else {
if (!args[0].respondsTo("exception")) {
throw runtime.newTypeError("exception class/object expected");
}
exception = args[0].callMethod(context, "exception", args[1]);
}
if (!runtime.fastGetClass("Exception").isInstance(exception)) {
throw runtime.newTypeError("exception object expected");
}
if (args.length == 3) {
((RubyException) exception).set_backtrace(args[2]);
}
if (runtime.getDebug().isTrue()) {
printExceptionSummary(context, runtime, (RubyException) exception);
}
throw new RaiseException((RubyException) exception);
}