Package com.aspectran.core.util
Class ExceptionUtils
- java.lang.Object
-
- com.aspectran.core.util.ExceptionUtils
-
public class ExceptionUtils extends java.lang.ObjectProvides utilities for manipulating and examining Throwable objects.Created: 2017. 10. 7.
- Since:
- 5.0.0
-
-
Constructor Summary
Constructors Constructor Description ExceptionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ThrowablegetRootCause(java.lang.Throwable t)Method that can be used to find the "root cause", innermost of chained (wrapped) exceptions.static java.lang.StringgetStacktrace(java.lang.Throwable throwable)Gets the stack trace from a Throwable as a String.static java.lang.IllegalArgumentExceptionthrowAsIAE(java.lang.Throwable t)Method that will wrap 't' as anIllegalArgumentExceptionif it is a checked exception; otherwise (runtime exception or error) throw as is.static java.lang.IllegalArgumentExceptionthrowAsIAE(java.lang.Throwable t, java.lang.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 java.lang.ThrowablethrowIfError(java.lang.Throwable t)Helper method that will check if argument is anError, and if so, (re)throw it; otherwise just return.static java.lang.ThrowablethrowIfIOE(java.lang.Throwable t)Helper method that will check if argument is anIOException, and if so, (re)throw it; otherwise just return.static java.lang.ThrowablethrowIfRTE(java.lang.Throwable t)Helper method that will check if argument is anRuntimeException, and if so, (re)throw it; otherwise just return.static java.lang.ThrowablethrowRootCauseIfIOE(java.lang.Throwable t)Method that works like by callinggetRootCause(java.lang.Throwable)and then either throwing it (if instanceofIOException), or return.static java.lang.IllegalArgumentExceptionunwrapAndThrowAsIAE(java.lang.Throwable t)Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentExceptionif it is a checked exception; otherwise (runtime exception or error) throw as is.static java.lang.IllegalArgumentExceptionunwrapAndThrowAsIAE(java.lang.Throwable t, java.lang.String msg)Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentExceptionif it is a checked exception; otherwise (runtime exception or error) throw as is.
-
-
-
Method Detail
-
getRootCause
public static java.lang.Throwable getRootCause(java.lang.Throwable t)
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
-
getStacktrace
public static java.lang.String getStacktrace(java.lang.Throwable throwable)
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:
throwable- theThrowableto be examined- Returns:
- the stack trace as generated by the exception's
printStackTrace(PrintWriter)method
-
throwIfError
public static java.lang.Throwable throwIfError(java.lang.Throwable t)
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
public static java.lang.Throwable throwIfRTE(java.lang.Throwable t)
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
public static java.lang.Throwable throwIfIOE(java.lang.Throwable t) throws java.io.IOExceptionHelper 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:
java.io.IOException- rethrow the IOException
-
throwRootCauseIfIOE
public static java.lang.Throwable throwRootCauseIfIOE(java.lang.Throwable t) throws java.io.IOExceptionMethod 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:
java.io.IOException- rethrow the IOException
-
throwAsIAE
public static java.lang.IllegalArgumentException throwAsIAE(java.lang.Throwable t)
Method that will wrap 't' as anIllegalArgumentExceptionif it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t- the Throwable to possibly propagate
-
throwAsIAE
public static java.lang.IllegalArgumentException throwAsIAE(java.lang.Throwable t, java.lang.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.- Parameters:
t- the Throwable to possibly propagatemsg- the detail message
-
unwrapAndThrowAsIAE
public static java.lang.IllegalArgumentException unwrapAndThrowAsIAE(java.lang.Throwable t)
Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentExceptionif it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t- the Throwable to possibly propagate
-
unwrapAndThrowAsIAE
public static java.lang.IllegalArgumentException unwrapAndThrowAsIAE(java.lang.Throwable t, java.lang.String msg)Method that will locate the innermost exception for given Throwable; and then wrap it as anIllegalArgumentExceptionif it is a checked exception; otherwise (runtime exception or error) throw as is.- Parameters:
t- the Throwable to possibly propagatemsg- the detail msg
-
-