Last active
June 19, 2017 10:29
-
-
Save jseteny/b9dfbbe1217e5d4d28c482fe51afe7e1 to your computer and use it in GitHub Desktop.
To use the root cause of an exception conveniently:
This file contains hidden or 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
| implicit class ThrowableWithRootCause(throwable: Throwable) { | |
| def rootCause: Throwable = cause(throwable) | |
| private def cause(t: Throwable): Throwable = t.getCause match { | |
| case null => t | |
| case _ => cause(t.getCause) | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
try {
throw new RuntimeException("Panic")
} catch {
case t: Throwable =>
System.err.println("An error has occured: ")
t.rootCause.printStackTrace(System.err)
}