// FIXME:This method should be module. @RubyLevelMethod(name = "raise", alias = "fail") public static RubyValue raise(RubyValue value, RubyArray args) { RubyExceptionValue e; if (null == args) { // With no arguments, raises the exception in $! or raises a RuntimeError if $! is nil. RubyValue v = GlobalVariables.get("$!"); if (RubyConstant.QNIL == v) { e = new RubyExceptionValue(RubyRuntime.RuntimeErrorClass, ""); } else { e = (RubyExceptionValue) v; } } else if (1 == args.size() && (args.get(0) instanceof RubyString)) { // With a single String argument, raises a RuntimeError with the string as a message. e = new RubyExceptionValue( RubyRuntime.RuntimeErrorClass, ((RubyString) args.get(0)).toString()); } else if (args.get(0) instanceof RubyExceptionValue) { // Otherwise, the first parameter should be the name of an Exception class // (or an object that returns an Exception when sent exception). The optional second // parameter sets the message associated with the exception, and the third parameter // is an array of callback information. e = (RubyExceptionValue) args.get(0); if (args.size() > 1) { e.setMessage(((RubyString) args.get(1)).toString()); } } else { RubyClass v = (RubyClass) args.get(0); e = new RubyExceptionValue(v, 1 == args.size() ? "" : ((RubyString) args.get(1)).toString()); } throw new RubyException(e); }
public RubyValue clone() { RubyExceptionValue cl = new RubyExceptionValue(this.class_, this.message_, this.throwable_); cl.setException(this.exception_); cl.doClone(this); return cl; }