public void exceptionRaised(RaiseException exception) {
    assert isCurrent();

    RubyException rubyException = exception.getException();
    Ruby runtime = rubyException.getRuntime();
    if (runtime.getSystemExit().isInstance(rubyException)) {
      runtime
          .getThreadService()
          .getMainThread()
          .raise(new IRubyObject[] {rubyException}, Block.NULL_BLOCK);
    } else if (abortOnException(runtime)) {
      RubyException systemExit;

      if (!runtime.is1_9()) {
        runtime.printError(rubyException);
        String message = rubyException.message.convertToString().toString();
        systemExit = RubySystemExit.newInstance(runtime, 1, message);
        systemExit.set_backtrace(rubyException.backtrace());
      } else {
        systemExit = rubyException;
      }

      runtime
          .getThreadService()
          .getMainThread()
          .raise(new IRubyObject[] {systemExit}, Block.NULL_BLOCK);
      return;
    } else if (runtime.getDebug().isTrue()) {
      runtime.printError(exception.getException());
    }
    exitingException = exception;
  }
Beispiel #2
0
  private IRubyObject prepareRaiseException(Ruby runtime, IRubyObject[] args, Block block) {
    if (args.length == 0) {
      IRubyObject lastException = errorInfo;
      if (lastException.isNil()) {
        return new RaiseException(runtime, runtime.getRuntimeError(), "", false).getException();
      }
      return lastException;
    }

    IRubyObject exception;
    ThreadContext context = getRuntime().getCurrentContext();

    if (args.length == 1) {
      if (args[0] instanceof RubyString) {
        return runtime.getRuntimeError().newInstance(context, args, block);
      }

      if (!args[0].respondsTo("exception")) {
        return runtime.newTypeError("exception class/object expected").getException();
      }
      exception = args[0].callMethod(context, "exception");
    } else {
      if (!args[0].respondsTo("exception")) {
        return runtime.newTypeError("exception class/object expected").getException();
      }

      exception = args[0].callMethod(context, "exception", args[1]);
    }

    if (!runtime.getException().isInstance(exception)) {
      return runtime.newTypeError("exception object expected").getException();
    }

    if (args.length == 3) {
      ((RubyException) exception).set_backtrace(args[2]);
    }

    return exception;
  }