io.scalecube.config.utils.ThrowableUtil Maven / Gradle / Ivy
package io.scalecube.config.utils;
public final class ThrowableUtil {
private ThrowableUtil() {
// Do not instantiate
}
/**
* Propagates throwable as-is if throwable is instance of {@link RuntimeException} or {@link
* Error}. In other case wraps into {@link RuntimeException}.
*
* @param throwable the throwable to be propagated
* @return runtime exception
*/
public static RuntimeException propagate(Throwable throwable) {
propagateIfInstanceOf(throwable, Error.class);
propagateIfInstanceOf(throwable, RuntimeException.class);
throw new RuntimeException(throwable);
}
private static void propagateIfInstanceOf(
Throwable throwable, Class type) throws X {
if (type.isInstance(throwable)) {
throw type.cast(throwable);
}
}
}