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 ofSpannerExceptionand 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.ABORTEDare always represented byAbortedException.
-
-
Constructor Summary
Constructors Constructor Description SpannerExceptionFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SpannerExceptionasSpannerException(Throwable t)Converts the givenThrowableto aSpannerException.static AbortedDueToConcurrentModificationExceptionnewAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)Constructs a newAbortedDueToConcurrentModificationExceptionthat can be re-thrown for a transaction that had already been aborted, but that the client application tried to use for additional statements.static AbortedDueToConcurrentModificationExceptionnewAbortedDueToConcurrentModificationException(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 AbortedDueToConcurrentModificationExceptionnewAbortedDueToConcurrentModificationException(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 SpannerBatchUpdateExceptionnewSpannerBatchUpdateException(ErrorCode code, String message, long[] updateCounts)static SpannerExceptionnewSpannerException(ErrorCode code, String message)static SpannerExceptionnewSpannerException(ErrorCode code, String message, Throwable cause)static SpannerExceptionnewSpannerException(io.grpc.Context context, Throwable cause)Creates a new exception based oncause.static SpannerExceptionnewSpannerException(Throwable cause)Creates a new exception based oncause.static SpannerExceptionpropagateInterrupt(InterruptedException e)static SpannerExceptionpropagateTimeout(TimeoutException e)Transforms aTimeoutExceptionto 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 aTimeoutExceptionto 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 givenThrowableto aSpannerException. Iftis already a (subclass of a)SpannerException,tis returned unaltered. Otherwise, a newSpannerExceptionis created withtas 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 newAbortedDueToConcurrentModificationExceptionthat 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. Ifcauseindicates cancellation,contextwill be inspected to establish the type of cancellation.Intended for internal library use; user code should use
newSpannerException(ErrorCode, String)instead of this method.
-
-