Package com.atlassian.bamboo.utils
Class Throwables
java.lang.Object
com.atlassian.bamboo.utils.Throwables
Convenience methods for working with
Throwables.- Since:
- 10.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetCausalChain(Throwable throwable) Copy from com.google.common.base.Throwables.propagateIfInstanceOf.static <X extends Throwable>
voidthrowIfInstanceOf(Throwable throwable, Class<X> declaredType) Copy from com.google.common.base.Throwables.propagateIfInstanceOf.static voidthrowIfUnchecked(Throwable throwable) Rethrow the giventhrowableif it is an instance ofRuntimeExceptionorError, i.e., if it is unchecked.
-
Constructor Details
-
Throwables
public Throwables()
-
-
Method Details
-
throwIfUnchecked
Rethrow the giventhrowableif it is an instance ofRuntimeExceptionorError, i.e., if it is unchecked.- Parameters:
throwable-
-
getCausalChain
Copy from com.google.common.base.Throwables.propagateIfInstanceOf.Gets a
Throwablecause chain as a list. The first entry in the list will bethrowablefollowed by its cause hierarchy. Note that this is a snapshot of the cause chain and will not reflect any subsequent changes to the cause chain.Here's an example of how it can be used to find specific types of exceptions in the cause chain:
Iterables.filter(Throwables.getCausalChain(e), IOException.class));
- Parameters:
throwable- the non-nullThrowableto extract causes from- Returns:
- an unmodifiable list containing the cause chain starting with
throwable - Throws:
IllegalArgumentException- if there is a loop in the causal chain
-
throwIfInstanceOf
public static <X extends Throwable> void throwIfInstanceOf(Throwable throwable, Class<X> declaredType) throws X Copy from com.google.common.base.Throwables.propagateIfInstanceOf.Throws
throwableif it is an instance ofdeclaredType. Example usage:for (Foo foo : foos) { try { foo.bar(); } catch (BarException | RuntimeException | Error t) { failure = t; } } if (failure != null) { throwIfInstanceOf(failure, BarException.class); throwIfUnchecked(failure); throw new AssertionError(failure); }- Throws:
X extends Throwable
-