# Class SpannerExceptionFactory (6.118.0)

6.118.0 (latest) 6.116.0 6.111.1 6.108.0 6.107.0 6.103.0 6.102.1 6.101.1 6.100.0 6.99.0 6.98.1 6.97.1 6.96.1 6.95.1 6.94.0 6.93.0 6.89.0 6.88.0 6.87.0 6.86.0 6.85.0 6.83.0 6.82.0 6.80.1 6.79.0 6.77.0 6.74.1 6.72.0 6.71.0 6.69.0 6.68.0 6.66.0 6.65.1 6.62.0 6.60.0 6.58.0 6.57.0 6.56.0 6.55.0 6.54.0 6.53.0 6.52.1 6.51.0 6.50.1 6.49.0 6.25.1 6.24.0 6.23.4 6.22.0 6.21.2 6.20.0 6.19.1 6.18.0 6.17.4 6.14.1

    public final class SpannerExceptionFactory

A factory for creating instances of [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) and its subtypes. All creation of
these exceptions is directed through the factory. This ensures that particular types of errors
are always expressed as the same concrete exception type. For example, exceptions of type [ErrorCode#ABORTED](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode#com_google_cloud_spanner_ErrorCode_ABORTED) are always represented by [AbortedException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException).

## Inheritance

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

## 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

### asSpannerException(Throwable t)

    public static SpannerException asSpannerException(Throwable t)

Converts the given [Throwable](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html) to a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException). If `t` is
already a (subclass of a) [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException), `t` is returned unaltered.
Otherwise, a new [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) is created with `t` as its cause.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

### causeAsRunTimeException(ExecutionException executionException)

    public static RuntimeException causeAsRunTimeException(ExecutionException executionException)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `executionException` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutionException.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html` |   |

### newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)

    public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)

Constructs a new [AbortedDueToConcurrentModificationException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException) that can be re-thrown for
a transaction that had already been aborted, but that the client application tried to use for
additional statements.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cause` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException` |   |

### newAbortedDueToConcurrentModificationException(AbortedException cause)

    public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedException cause)

Constructs a specific aborted exception that should only be thrown by a connection after an
internal retry aborted due to concurrent modifications.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cause` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException` |   |

### newAbortedDueToConcurrentModificationException(AbortedException cause, SpannerException databaseError)

    public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedException cause, SpannerException databaseError)

Constructs a specific aborted exception that should only be thrown by a connection after an
internal retry aborted because a database call caused an exception that did not happen during
the original attempt.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `cause` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedException` |
| `databaseError` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.AbortedDueToConcurrentModificationException` |   |

### newDmlBatchUpdateCountVerificationFailedException(long\[\] expected, long\[\] actual)

    public static DmlBatchUpdateCountVerificationFailedException newDmlBatchUpdateCountVerificationFailedException(long[] expected, long[] actual)

Constructs a specific error that

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `expected` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |
| `actual` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.DmlBatchUpdateCountVerificationFailedException` |   |

### newSpannerBatchUpdateException(ErrorCode code, String message, long\[\] updateCounts)

    public static SpannerBatchUpdateException newSpannerBatchUpdateException(ErrorCode code, String message, long[] updateCounts)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode` |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `updateCounts` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerBatchUpdateException` |   |

### newSpannerException(ErrorCode code, String message)

    public static SpannerException newSpannerException(ErrorCode code, String message)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode` |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

### newSpannerException(ErrorCode code, String message, Throwable cause)

    public static SpannerException newSpannerException(ErrorCode code, String message, Throwable cause)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.ErrorCode` |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `cause` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

### newSpannerException(Context context, Throwable cause)

    public static SpannerException newSpannerException(Context context, Throwable cause)

Creates a new exception based on `cause`. If `cause` indicates cancellation, `
context` will be inspected to establish the type of cancellation.

Intended for internal library use; user code should use [#newSpannerException(ErrorCode, String)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerExceptionFactory#com_google_cloud_spanner_SpannerExceptionFactory_newSpannerException_com_google_cloud_spanner_ErrorCode_java_lang_String_) instead of this method.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `io.grpc.Context` |
| `cause` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

### newSpannerException(Throwable cause)

    public static SpannerException newSpannerException(Throwable cause)

Creates a new exception based on `cause`.

Intended for internal library use; user code should use [#newSpannerException(ErrorCode, String)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerExceptionFactory#com_google_cloud_spanner_SpannerExceptionFactory_newSpannerException_com_google_cloud_spanner_ErrorCode_java_lang_String_) instead of this method.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

### propagateInterrupt(InterruptedException e)

    public static SpannerException propagateInterrupt(InterruptedException e)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `e` | `https://docs.oracle.com/javase/8/docs/api/java/lang/InterruptedException.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

### propagateTimeout(TimeoutException e)

    public static SpannerException propagateTimeout(TimeoutException e)

Transforms a `TimeoutException` to a `SpannerException`.

     
     try {
       Spanner spanner = SpannerOptions.getDefaultInstance();
       spanner
           .getDatabaseAdminClient()
           .createDatabase("[INSTANCE_ID]", "[DATABASE_ID]", [STATEMENTS])
           .get();
     } catch (TimeoutException e) {
       propagateTimeout(e);
     }
     
     
| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `e` | `https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/TimeoutException.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException` |   |

## Constructors

### SpannerExceptionFactory()

    public SpannerExceptionFactory()