Package com.atlassian.bamboo.utils
Class Throwables
java.lang.Object
com.atlassian.bamboo.utils.Throwables
Convenience methods for working with
Throwable
s.- Since:
- 10.0
-
Constructor Summary
-
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 void
throwIfUnchecked
(Throwable throwable) Rethrow the giventhrowable
if it is an instance ofRuntimeException
orError
, i.e., if it is unchecked.
-
Constructor Details
-
Throwables
public Throwables()
-
-
Method Details
-
throwIfUnchecked
Rethrow the giventhrowable
if it is an instance ofRuntimeException
orError
, i.e., if it is unchecked.- Parameters:
throwable
-
-
getCausalChain
Copy from com.google.common.base.Throwables.propagateIfInstanceOf.Gets a
Throwable
cause chain as a list. The first entry in the list will bethrowable
followed 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-nullThrowable
to 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
throwable
if 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
-