public final class SpannerExceptionFactory extends Object
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
are always represented by AbortedException
.Constructor and Description |
---|
SpannerExceptionFactory() |
Modifier and Type | Method and Description |
---|---|
static SpannerException |
asSpannerException(Throwable t)
Converts the given
Throwable to a SpannerException . |
static AbortedDueToConcurrentModificationException |
newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)
Constructs a new
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. |
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(Context context,
Throwable cause)
Creates a new exception based on
cause . |
static SpannerException |
newSpannerException(ErrorCode code,
String message) |
static SpannerException |
newSpannerException(ErrorCode code,
String message,
Throwable cause) |
static SpannerException |
newSpannerException(Throwable cause)
Creates a new exception based on
cause . |
static SpannerException |
propagateInterrupt(InterruptedException e) |
static SpannerException |
propagateTimeout(TimeoutException e)
Transforms a
TimeoutException to a SpannerException . |
public static SpannerException newSpannerException(ErrorCode code, @Nullable String message)
public static SpannerException newSpannerException(ErrorCode code, @Nullable String message, @Nullable Throwable cause)
public static SpannerException propagateInterrupt(InterruptedException e)
public static SpannerException propagateTimeout(TimeoutException e)
TimeoutException
to a SpannerException
.
try {
Spanner spanner = SpannerOptions.getDefaultInstance();
spanner
.getDatabaseAdminClient()
.createDatabase("[INSTANCE_ID]", "[DATABASE_ID]", [STATEMENTS])
.get();
} catch (TimeoutException e) {
propagateTimeout(e);
}
public static SpannerException asSpannerException(Throwable t)
Throwable
to a SpannerException
. If t
is
already a (subclass of a) SpannerException
, t
is returned unaltered.
Otherwise, a new SpannerException
is created with t
as its cause.public static SpannerException newSpannerException(Throwable cause)
cause
.
Intended for internal library use; user code should use newSpannerException(ErrorCode, String)
instead of this method.
public static SpannerBatchUpdateException newSpannerBatchUpdateException(ErrorCode code, String message, long[] updateCounts)
public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedException cause)
public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedException cause, SpannerException databaseError)
public static AbortedDueToConcurrentModificationException newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)
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.public static SpannerException newSpannerException(@Nullable Context context, Throwable cause)
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)
instead of this method.
Copyright © 2022 Google LLC. All rights reserved.