|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.ThrowableUtil
public final class ThrowableUtil
Provides static utility methods for Throwables.
This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).
Nested Class Summary | |
---|---|
static class |
ThrowableUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private static int |
typicalTypeAndMessageSize
|
Constructor Summary | |
---|---|
private |
ThrowableUtil()
This private constructor suppresses the default (public) constructor, ensuring non-instantiability. |
Method Summary | |
---|---|
static String |
getStackTraceString(StackTraceElement[] stackTrace)
Returns a String that represent's stackTrace 's elements. |
static String |
getStackTraceString(Throwable t)
Returns a String that represents t's stack trace. |
static String |
getTypeAndMessage(Throwable t)
Returns a String that concatenates t's type (i.e. classname) and message into a single String. |
static RuntimeException |
toRuntimeException(Throwable t)
Always returns a RuntimeException using this sequential logic: if t == null, returns a new RuntimeException which has a null cause else if t is an instanceof Error, returns a new RuntimeException which has t as its cause else if t is an instanceof RuntimeException, returns t itself else if t is an instanceof Exception, then it must be a checked Exception, so it returns a new RuntimeException which has t as its cause else t is an actual Throwable instance (or some unknown subclass), so it returns a new RuntimeException which has t as its cause This method is usually called to convert checked Exceptions into unchecked ones. |
static String |
toString(Throwable t)
Returns a String that represents t in its entirety. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int typicalTypeAndMessageSize
Constructor Detail |
---|
private ThrowableUtil()
Method Detail |
---|
public static RuntimeException toRuntimeException(Throwable t)
This method is usually called to convert checked Exceptions into unchecked ones.
One example where this is useful is if you want to initialize a field by calling a method: it turns out that such a method cannot throw a checked Exception, so it must have a try-catch block, and it may be convenient for the catch to simply pass whatever it catches to this method and rethrow the result.
t
- the original cause; may be nullpublic static String toString(Throwable t) throws IllegalArgumentException
getTypeAndMessage
(t).
The next lines come from calling getStackTraceString
(t).
Finally, if t has a cause,
then that Throwable's information is appended onto the result in a recursive call to this method.
IllegalArgumentException
- if t == nullpublic static String getTypeAndMessage(Throwable t) throws IllegalArgumentException
If t is an instance of ParseException
, then it also appends the error offset.
IllegalArgumentException
- if t is nullpublic static String getStackTraceString(Throwable t) throws IllegalArgumentException
IllegalArgumentException
- if t == nullpublic static String getStackTraceString(StackTraceElement[] stackTrace) throws IllegalArgumentException
String
that represent's stackTrace
's elements.
IllegalArgumentException
- if stackTrace == null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |