Created
November 20, 2012 09:37
-
-
Save jmiettinen/4116981 to your computer and use it in GitHub Desktop.
Exceptions with deep causes. JRuby only shows the latest level, i.e. 'Exception on level 8' without any insight into the deeper causes.
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
require 'java' | |
$CLASSPATH << File.expand_path('..', __FILE__) | |
Java::NestedExceptionTest.new.throw_nested_exceptions 8 |
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
public class NestedExceptionTest { | |
public void throwNestedExceptions(int n) { | |
if (n > 0) { | |
try { | |
throwNestedExceptions(n-1); | |
} catch (Exception e) { | |
throw new RuntimeException("Exception on level " + n, e); | |
} | |
} else { | |
throw new RuntimeException("Root cause!"); | |
} | |
} | |
public static void main(String[] ignored) { | |
new NestedExceptionTest().throwNestedExceptions(8); | |
} | |
} |
I don't think Ruby can throw nested exceptions; I believe JRuby mimics this behavior.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would expect the JRuby stack trace to contain some information about the root cause but instead it only shows
without a mention of the root cause.
So, how should I get that information saved, say, when logging? Should I manually inspect
NativeException
and see what it contains?