Package org.apache.sshd.common.util
Class ExceptionUtils
- java.lang.Object
-
- org.apache.sshd.common.util.ExceptionUtils
-
public final class ExceptionUtils extends Object
- Author:
- Apache MINA SSHD Project
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Throwable>
TaccumulateException(T current, T extra)
Used to "accumulate" exceptions of the same type.static Throwable
peelException(Throwable t)
Attempts to get to the "effective" exception being thrown, by taking care of some known exceptions that wrap the original thrown one.static Throwable
resolveExceptionCause(Throwable t)
static void
rethrowAsIoException(Throwable e)
static RuntimeException
toRuntimeException(Throwable t)
static RuntimeException
toRuntimeException(Throwable t, boolean peelThrowable)
Converts a thrown generic exception to aRuntimeException
-
-
-
Method Detail
-
rethrowAsIoException
public static void rethrowAsIoException(Throwable e) throws IOException
- Throws:
IOException
-
accumulateException
public static <T extends Throwable> T accumulateException(T current, T extra)
Used to "accumulate" exceptions of the same type. If the current exception isnull
then the new one becomes the current, otherwise the new one is added as a suppressed exception to the current one- Type Parameters:
T
- The exception type- Parameters:
current
- The current exceptionextra
- The extra/new exception- Returns:
- The resolved exception
- See Also:
Throwable.addSuppressed(Throwable)
-
resolveExceptionCause
public static Throwable resolveExceptionCause(Throwable t)
- Parameters:
t
- The originalThrowable
- ignored ifnull
- Returns:
- If
Throwable.getCause()
is non-null
then the cause, otherwise the original exception -null
if the original exception wasnull
-
peelException
public static Throwable peelException(Throwable t)
Attempts to get to the "effective" exception being thrown, by taking care of some known exceptions that wrap the original thrown one.- Parameters:
t
- The originalThrowable
- ignored ifnull
- Returns:
- The effective exception - same as input if not a wrapper
-
toRuntimeException
public static RuntimeException toRuntimeException(Throwable t, boolean peelThrowable)
Converts a thrown generic exception to aRuntimeException
- Parameters:
t
- The original thrown exceptionpeelThrowable
- Whether to determine the root cause by "peeling" any enclosing exceptions- Returns:
- The thrown cause if already a runtime exception, otherwise a runtime exception of the resolved exception as its cause
- See Also:
peelException(Throwable)
-
toRuntimeException
public static RuntimeException toRuntimeException(Throwable t)
-
-