de.team33.libs.exceptional.v3.WrappedException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lib-exceptional Show documentation
Show all versions of lib-exceptional Show documentation
Provides wrapping and unwrapping checked exceptions.
package de.team33.libs.exceptional.v3;
/**
* A RuntimeException used to wrap checked exceptions where it is not allowed to throw or pass them directly.
*/
public class WrappedException extends RuntimeException {
/**
* Initializes a new instance.
*/
public WrappedException(final Throwable cause) {
super(cause.getMessage(), cause);
}
/**
* Rethrows the cause of this WrappedException if it matches the given exception type.
* Otherwise it returns this WrappedException.
*/
public final WrappedException reThrowCauseIf(final Class xClass) throws X {
final Throwable cause = getCause();
if (xClass.isInstance(cause)) {
throw xClass.cast(cause);
}
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy