Package com.aspectran.utils
Class ExceptionUtils
java.lang.Object
com.aspectran.utils.ExceptionUtils
Provides utilities for manipulating and examining Throwable objects.
Created: 2017. 10. 7.
- Since:
- 5.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Throwable
Method that can be used to find the "root cause", innermost of chained (wrapped) exceptions.static Exception
static String
static String
static String
Gets the stack trace from a Throwable as a String.static IllegalArgumentException
Method that will wrap 't' as anIllegalArgumentException
if it is a checked exception; otherwise (runtime exception or error) throw as is.static IllegalArgumentException
throwAsIAE
(Throwable t, String msg) Method that will wrap 't' as anIllegalArgumentException
(and with specified message) if it is a checked exception; otherwise (runtime exception or error) throw as is.static Throwable
Helper method that will check if argument is anError
, and if so, (re)throw it; otherwise just return.static Throwable
Helper method that will check if argument is anIOException
, and if so, (re)throw it; otherwise just return.static Throwable
Helper method that will check if argument is anRuntimeException
, and if so, (re)throw it; otherwise just return.static Throwable
Method that works like by callinggetRootCause(java.lang.Throwable)
and then either throwing it (if instanceofIOException
), or return.static IllegalArgumentException
Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentException
if it is a checked exception; otherwise (runtime exception or error) throw as is.static IllegalArgumentException
unwrapAndThrowAsIAE
(Throwable t, String msg) Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentException
if it is a checked exception; otherwise (runtime exception or error) throw as is.
-
Constructor Details
-
ExceptionUtils
public ExceptionUtils()
-
-
Method Details
-
getRootCause
Method that can be used to find the "root cause", innermost of chained (wrapped) exceptions.- Parameters:
t
- the Throwable to possibly propagate- Returns:
- the root cause
-
getRootCauseException
-
getStacktrace
Gets the stack trace from a Throwable as a String.The result of this method vary by JDK version as this method uses
Throwable.printStackTrace(java.io.PrintWriter)
. On JDK1.3 and earlier, the cause exception will not be shown unless the specified throwable alters printStackTrace.- Parameters:
t
- theThrowable
to be examined- Returns:
- the stack trace as generated by the exception's
printStackTrace(PrintWriter)
method
-
getSimpleMessage
-
getRootCauseSimpleMessage
-
throwIfError
Helper method that will check if argument is anError
, and if so, (re)throw it; otherwise just return.- Parameters:
t
- the Throwable to possibly propagate- Returns:
- the Throwable
-
throwIfRTE
Helper method that will check if argument is anRuntimeException
, and if so, (re)throw it; otherwise just return.- Parameters:
t
- the Throwable to possibly propagate- Returns:
- the Throwable
-
throwIfIOE
Helper method that will check if argument is anIOException
, and if so, (re)throw it; otherwise just return.- Parameters:
t
- the Throwable to possibly propagate- Returns:
- the Throwable
- Throws:
IOException
- rethrow the IOException
-
throwRootCauseIfIOE
Method that works like by callinggetRootCause(java.lang.Throwable)
and then either throwing it (if instanceofIOException
), or return.- Parameters:
t
- the Throwable to possibly propagate- Returns:
- the Throwable
- Throws:
IOException
- rethrow the IOException
-
throwAsIAE
Method that will wrap 't' as anIllegalArgumentException
if it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t
- the Throwable to possibly propagate
-
throwAsIAE
Method that will wrap 't' as anIllegalArgumentException
(and with specified message) if it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t
- the Throwable to possibly propagatemsg
- the detail message
-
unwrapAndThrowAsIAE
Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentException
if it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t
- the Throwable to possibly propagate
-
unwrapAndThrowAsIAE
Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentException
if it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t
- the Throwable to possibly propagatemsg
- the detail msg
-