# Class Throwables (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Throwables)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.util.Throwables)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.Throwables)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.Throwables)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.Throwables)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.Throwables)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.Throwables)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.Throwables)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.Throwables)

    public final class Throwables

Static utility methods pertaining to instances of [Throwable](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html).

NOTE: proxy for the Guava implementation of com.google.common.base.Throwables.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> Throwables

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### \<X\>propagateIfPossible(Throwable throwable, Class\<X\> declaredType)

    public static void <X>propagateIfPossible(Throwable throwable, Class<X> declaredType)

Propagates `throwable` exactly as-is, if and only if it is an instance of [RuntimeException](https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html), Error, or `declaredType`. Example usage:

try {
someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
handle(e);
} catch (Throwable t) {
Throwables.propagateIfPossible(t, OtherException.class);
throw new RuntimeException("unexpected", t);
}

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `throwable` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` throwable (may be `null`) |
| `declaredType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<X>` the single checked exception type declared by the calling method |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `X` |   |

### propagate(Throwable throwable)

    public static RuntimeException propagate(Throwable throwable)

Propagates `throwable` as-is if it is an instance of [RuntimeException](https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html) or Error, or else as a last resort, wraps it in a `RuntimeException` then propagates.

This method always throws an exception. The `RuntimeException` return type is only for
client code to make Java type system happy in case a return value is required by the enclosing
method. Example usage:

T doSomething() {
try {
return someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
return handle(e);
} catch (Throwable t) {
throw Throwables.propagate(t);
}
}

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `throwable` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` the Throwable to propagate |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html` | nothing will ever be returned; this return type is only for your convenience, as illustrated in the example above |

### propagateIfPossible(Throwable throwable)

    public static void propagateIfPossible(Throwable throwable)

Propagates `throwable` exactly as-is, if and only if it is an instance of [RuntimeException](https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html) or Error. Example usage:

try {
someMethodThatCouldThrowAnything();
} catch (IKnowWhatToDoWithThisException e) {
handle(e);
} catch (Throwable t) {
Throwables.propagateIfPossible(t);
throw new RuntimeException("unexpected", t);
}

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `throwable` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` throwable (may be `null`) |