java.lang.Object
is.codion.common.utilities.exceptions.Exceptions
Exception handling utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeExceptionReturns the givenThrowablein case it is a RuntimeException or else a RuntimeException wrapping it.static RuntimeExceptionReturns the givenThrowablein case it is a RuntimeException or else a RuntimeException wrapping it.static Throwableunwrap(Throwable throwable, Collection<Class<? extends Throwable>> unwrap) Unwraps the given throwable, following the cause chain while each cause's exact class is one of the given types.
-
Method Details
-
runtime
Returns the given
Throwablein case it is a RuntimeException or else a RuntimeException wrapping it.Note that if a new wrapper RuntimeException is created, it has the stacktrace of the original throwable, as well as its message, while keeping the original throwable as its cause.
- Parameters:
throwable- the throwable- Returns:
- the throwable itself if it is a RuntimeException, otherwise a RuntimeException wrapping it
-
runtime
@SafeVarargs public static RuntimeException runtime(Throwable throwable, Class<? extends Throwable>... unwrap) Returns the given
Throwablein case it is a RuntimeException or else a RuntimeException wrapping it.Note that if a new wrapper RuntimeException is created, it has the stacktrace of the unwrapped throwable, as well as its message, while keeping the unwrapped throwable as its cause.
- Parameters:
throwable- the throwableunwrap- the exception types to unwrap before wrapping- Returns:
- the unwrapped throwable itself if it is a RuntimeException, otherwise a RuntimeException wrapping it
-
unwrap
Unwraps the given throwable, following the cause chain while each cause's exact class is one of the given types. Note that matching is by exact class; subclasses of a listed type are not unwrapped.- Parameters:
throwable- the exception to unwrapunwrap- the exception types to unwrap- Returns:
- the unwrapped exception
-