# Exception DatastoreException (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    public final class DatastoreException extends BaseHttpServiceException

Datastore service exception.
See Also: [Google Cloud Datastore error codes](https://cloud.google.com/datastore/docs/concepts/errors#Error_Codes)

## Inherited Members

com.google.cloud.BaseServiceException.equals(java.lang.Object) com.google.cloud.BaseServiceException.getCode() com.google.cloud.BaseServiceException.getDebugInfo() com.google.cloud.BaseServiceException.getLocation() com.google.cloud.BaseServiceException.getReason() com.google.cloud.BaseServiceException.hashCode() com.google.cloud.BaseServiceException.isRetryable() com.google.cloud.BaseServiceException.isRetryable(boolean,java.io.IOException) com.google.cloud.BaseServiceException.isRetryable(java.lang.Integer,java.lang.String,boolean,java.util.Set\<com.google.cloud.BaseServiceException.Error\>) com.google.cloud.BaseServiceException.translate(com.google.cloud.RetryHelper.RetryHelperException) com.google.cloud.BaseServiceException.translate(java.util.concurrent.ExecutionException) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [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.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.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-) [Throwable.addSuppressed(Throwable)](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#addSuppressed-java.lang.Throwable-) [Throwable.fillInStackTrace()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#fillInStackTrace--) [Throwable.getCause()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#getCause--) [Throwable.getLocalizedMessage()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#getLocalizedMessage--) [Throwable.getMessage()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#getMessage--) [Throwable.getStackTrace()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#getStackTrace--) [Throwable.getSuppressed()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#getSuppressed--) [Throwable.initCause(Throwable)](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#initCause-java.lang.Throwable-) [Throwable.printStackTrace()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#printStackTrace--) [Throwable.printStackTrace(PrintStream)](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#printStackTrace-java.io.PrintStream-) [Throwable.printStackTrace(PrintWriter)](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#printStackTrace-java.io.PrintWriter-) [Throwable.setStackTrace(StackTraceElement\[\])](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#setStackTrace-java.lang.StackTraceElement[]-) [Throwable.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#toString--)

## Static Methods

### extractStatusCode(Throwable throwable)

    public static String extractStatusCode(Throwable throwable)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Extracts the status code name from the given throwable. Walks the exception cause chain looking
for a [DatastoreException](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreException) that carries a reason string representing the status code
(e.g. "ABORTED", "UNAVAILABLE"). The reason is set from com.google.api.gax.rpc.StatusCode.Code which is transport-neutral, supporting both gRPC and
HttpJson. Falls back to "UNKNOWN" if the status cannot be determined.

Note: Some [DatastoreException](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreException) instances are constructed without a reason (e.g. via
[DatastoreException#DatastoreException(int, String, Throwable)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreException#com_google_cloud_datastore_DatastoreException_DatastoreException_int_java_lang_String_java_lang_Throwable_)). If all [DatastoreException](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreException) instances in the cause chain have a null or empty reason, this method
returns "UNKNOWN" even if the underlying error carries a meaningful status.

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

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | the status code name, or "UNKNOWN" if not determinable |

## Constructors

### DatastoreException(int code, String message, String reason)

    public DatastoreException(int code, String message, String reason)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `reason` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

### DatastoreException(int code, String message, String reason, boolean idempotent, Throwable cause)

    public DatastoreException(int code, String message, String reason, boolean idempotent, Throwable cause)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `reason` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `idempotent` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `cause` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html` |

### DatastoreException(int code, String message, String reason, Throwable cause)

    public DatastoreException(int code, String message, String reason, Throwable cause)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `message` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `reason` | `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` |

### DatastoreException(int code, String message, Throwable cause)

    public DatastoreException(int code, String message, Throwable cause)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `code` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `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` |

### DatastoreException(IOException exception)

    public DatastoreException(IOException exception)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `exception` | `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |