Package com.google.cloud.spanner
Class SpannerExceptionFactory
- java.lang.Object
-
- com.google.cloud.spanner.SpannerExceptionFactory
-
public final class SpannerExceptionFactory extends Object
A factory for creating instances ofSpannerException
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 typeErrorCode.ABORTED
are always represented byAbortedException
.
-
-
Constructor Summary
Constructors Constructor Description SpannerExceptionFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SpannerException
asSpannerException(Throwable t)
Converts the givenThrowable
to aSpannerException
.static AbortedDueToConcurrentModificationException
newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)
Constructs a newAbortedDueToConcurrentModificationException
that can be re-thrown for a transaction that had already been aborted, but that the client application tried to use for additional statements.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.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.static SpannerBatchUpdateException
newSpannerBatchUpdateException(ErrorCode code, String message, long[] updateCounts)
static SpannerException
newSpannerException(ErrorCode code, String message)
static SpannerException
newSpannerException(ErrorCode code, String message, Throwable cause)
static SpannerException
newSpannerException(io.grpc.Context context, Throwable cause)
Creates a new exception based oncause
.static SpannerException
newSpannerException(Throwable cause)
Creates a new exception based oncause
.static SpannerException
propagateInterrupt(InterruptedException e)
static SpannerException
propagateTimeout(TimeoutException e)
Transforms aTimeoutException
to aSpannerException
.
-
-
-
Method Detail
-
newSpannerException
public static SpannerException newSpannerException(ErrorCode code, @Nullable String message)
-
newSpannerException
public static SpannerException newSpannerException(ErrorCode code, @Nullable String message, @Nullable Throwable cause)
-
propagateInterrupt
public static SpannerException propagateInterrupt(InterruptedException e)
-
propagateTimeout
public static SpannerException propagateTimeout(TimeoutException e)
Transforms aTimeoutException
to aSpannerException
.try { Spanner spanner = SpannerOptions.getDefaultInstance(); spanner .getDatabaseAdminClient() .createDatabase("[INSTANCE_ID]", "[DATABASE_ID]", [STATEMENTS]) .get(); } catch (TimeoutException e) { propagateTimeout(e); }
-
asSpannerException
public static SpannerException asSpannerException(Throwable t)
Converts the givenThrowable
to aSpannerException
. Ift
is already a (subclass of a)SpannerException
,t
is returned unaltered. Otherwise, a newSpannerException
is created witht
as its cause.
-
newSpannerException
public static SpannerException newSpannerException(Throwable cause)
Creates a new exception based oncause
.Intended for internal library use; user code should use
newSpannerException(ErrorCode, String)
instead of this method.
-
newSpannerBatchUpdateException
public static SpannerBatchUpdateException newSpannerBatchUpdateException(ErrorCode code, String message, long[] updateCounts)
-
newAbortedDueToConcurrentModificationException
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.
-
newAbortedDueToConcurrentModificationException
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.
-
newAbortedDueToConcurrentModificationException
public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)
Constructs a newAbortedDueToConcurrentModificationException
that can be re-thrown for a transaction that had already been aborted, but that the client application tried to use for additional statements.
-
newSpannerException
public static SpannerException newSpannerException(@Nullable io.grpc.Context context, Throwable cause)
Creates a new exception based oncause
. Ifcause
indicates cancellation,context
will be inspected to establish the type of cancellation.Intended for internal library use; user code should use
newSpannerException(ErrorCode, String)
instead of this method.
-
-