Created
February 14, 2012 10:26
-
-
Save purplefox/1825567 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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