Skip to content

Instantly share code, notes, and snippets.

@purplefox
Created February 14, 2012 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purplefox/1825567 to your computer and use it in GitHub Desktop.
Save purplefox/1825567 to your computer and use it in GitHub Desktop.
Using JRuby 1.6.2. Running a JRuby script from Java 7, JUnit test case:
public class RubyStdErrTest extends TestCase {
public void testCatchRubyException() throws Exception {
ScriptingContainer container = new ScriptingContainer(LocalContextScope.SINGLETHREAD);
String script = "raise 'Foo'";
try {
container.runScriptlet(script);
} catch (Throwable t) {
System.out.println("Caught the exception in Java: " + t.getMessage());
}
}
}
Output:
RuntimeError: Foo
(root) at <script>:1
Caught the exception in Java: (RuntimeError) Foo
I.e., something is logging the exception (to stderr?) before it is caught in the Java code. Ideally I would to be able to disable the internal exception logging and handle it all myself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment