Package org.jruby

Examples of org.jruby.RubyException


        String uri = null;      // TODO: implement me

        if (statement != null)
            query = driver.statementToString(statement);

        RubyException doSqlError = (RubyException) driverError.newInstance(
                runtime.getCurrentContext(),
                new IRubyObject[]{
                    runtime.newString(message),
                    runtime.newFixnum(code),
                    (sqlState != null) ? runtime.newString(sqlState) : runtime.getNil(),
View Full Code Here


    }
   
    private RaiseException newRefError(String message) {
        Ruby runtime = getRuntime();
        ThreadContext context = runtime.getCurrentContext();
        RubyException exception =
                (RubyException)runtime.getClass("WeakRef").getClass("RefError").newInstance(context,
                new IRubyObject[] {runtime.newString(message)}, Block.NULL_BLOCK);
       
        RaiseException re = new RaiseException(exception);
        return re;
View Full Code Here

            // package name. (and seriously, folks, look into best practices...)
            IRubyObject previousErrorInfo = RuntimeHelpers.getErrorInfo(runtime);
            try {
                return getProxyClass(runtime, runtime.getJavaSupport().loadJavaClassQuiet(fullName));
            } catch (RaiseException re) { /* expected */
                RubyException rubyEx = re.getException();
                if (rubyEx.kind_of_p(context, runtime.getStandardError()).isTrue()) {
                    RuntimeHelpers.setErrorInfo(runtime, previousErrorInfo);
                }
            } catch (Exception e) { /* expected */ }

            // Haven't found a class, continue on as though it were a package
View Full Code Here

        if (Character.isLowerCase(name.charAt(0))) {
            // this covers primitives and (unlikely) lower-case class names
            try {
                return getProxyClass(runtime, runtime.getJavaSupport().loadJavaClassQuiet(name));
            } catch (RaiseException re) { /* not primitive or lc class */
                RubyException rubyEx = re.getException();
                if (rubyEx.kind_of_p(context, runtime.getStandardError()).isTrue()) {
                    RuntimeHelpers.setErrorInfo(runtime, runtime.getNil());
                }
            } catch (Exception e) { /* not primitive or lc class */ }

            // TODO: check for Java reserved names and raise exception if encountered
View Full Code Here

        return newGzipFileError(runtime, "LengthError", message);
    }

    static RaiseException newGzipFileError(Ruby runtime, String klass, String message) {
        RubyClass errorClass = runtime.getModule("Zlib").getClass("GzipFile").getClass(klass);
        RubyException excn = RubyException.newException(runtime, errorClass, message);
        if (runtime.is1_9()) {
            // TODO: not yet supported. rewrite GzipReader/Writer with Inflate/Deflate?
            excn.setInstanceVariable("@input", runtime.getNil());
        }
        return new RaiseException(excn, true);
    }
View Full Code Here

                    "not in gzip format");
            if (getRuntime().is1_9()) {
                byte[] input = io.getAvailIn();
                if (input != null && input.length > 0) {
                    ByteList i = new ByteList(input, 0, input.length);
                    RubyException rubye = re.getException();
                    rubye.setInstanceVariable("@input",
                            RubyString.newString(getRuntime(), i));
                }
            }
            throw re;
        }
View Full Code Here

  private Ruby interpreter;
  private RubyException exception;

  public void setUp() {
    interpreter = Ruby.newInstance();
    exception = new RubyException(interpreter, interpreter.getClass("StandardError"), "test");
  }
View Full Code Here

    private void verifyExit(RubyObject expectedStatus, String argument) throws Exception {
        try {
            eval("exit " + argument);
            fail("Expected a SystemExit to be thrown by calling exit.");
        } catch (RaiseException re) {
          RubyException raisedException = re.getException();
          if (runtime.getClass("SystemExit").isInstance(raisedException)) {
              IRubyObject status = raisedException.callMethod(runtime.getCurrentContext(), "status");
              assertEquals(expectedStatus, status);
          } else {
            throw re;
          }
        }
View Full Code Here

        RubyInstanceConfig config = new RubyInstanceConfig() {{
            setInput(System.in); setOutput(System.out); setError(new PrintStream(err)); setObjectSpaceEnabled(false);
            setTraceType(TraceType.traceTypeFor("mri"));
        }};
        Ruby ruby = Ruby.newInstance(config);
        RubyException exception = (RubyException)runtime.getClass("NameError").newInstance(ruby.getCurrentContext(), new IRubyObject[]{ruby.newString("A message")},  Block.NULL_BLOCK);
        RubyString[] lines = new RubyString[]{
            RubyString.newString(ruby, "Line 1"),
            RubyString.newString(ruby, "Line 2"),
        };
        RubyArray backtrace = RubyArray.newArray(ruby, Arrays.<IRubyObject>asList(lines));
        exception.set_backtrace(backtrace);
        ruby.printError(exception);
        assertEquals("Line 1: A message (NameError)\n\tfrom Line 2\n", err.toString());
    }
View Full Code Here

        RubyInstanceConfig config = new RubyInstanceConfig() {{
            setInput(System.in); setOutput(System.out); setError(new PrintStream(err)); setObjectSpaceEnabled(false);
            setTraceType(TraceType.traceTypeFor("mri"));
        }};
        Ruby ruby = Ruby.newInstance(config);
        RubyException exception = (RubyException)runtime.getClass("NameError").newInstance(ruby.getCurrentContext(), new IRubyObject[]{ruby.newString("A message")},  Block.NULL_BLOCK);
        ruby.printError(exception);
        //        assertEquals(":[0,0]:[0,7]: A message (NameError)\n", err.toString());
    }
View Full Code Here

TOP

Related Classes of org.jruby.RubyException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.