Class SpannerExceptionFactory (6.72.0)

public final class SpannerExceptionFactory

A factory for creating instances of 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.

Inheritance

java.lang.Object > SpannerExceptionFactory

Static Methods

asSpannerException(Throwable t)

public static SpannerException asSpannerException(Throwable t)

Converts the given 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.

Parameter
Name Description
t Throwable
Returns
Type Description
SpannerException

newAbortedDueToConcurrentModificationException(AbortedDueToConcurrentModificationException cause)

public 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.

Parameter
Name Description
cause AbortedDueToConcurrentModificationException
Returns
Type Description
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 AbortedException
Returns
Type Description
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 AbortedException
databaseError SpannerException
Returns
Type Description
AbortedDueToConcurrentModificationException

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

public static SpannerBatchUpdateException newSpannerBatchUpdateException(ErrorCode code, String message, long[] updateCounts)
Parameters
Name Description
code ErrorCode
message String
updateCounts long[]
Returns
Type Description
SpannerBatchUpdateException

newSpannerException(ErrorCode code, String message)

public static SpannerException newSpannerException(ErrorCode code, String message)
Parameters
Name Description
code ErrorCode
message String
Returns
Type Description
SpannerException

newSpannerException(ErrorCode code, String message, Throwable cause)

public static SpannerException newSpannerException(ErrorCode code, String message, Throwable cause)
Parameters
Name Description
code ErrorCode
message String
cause Throwable
Returns
Type Description
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) instead of this method.

Parameters
Name Description
context io.grpc.Context
cause Throwable
Returns
Type Description
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) instead of this method.

Parameter
Name Description
cause Throwable
Returns
Type Description
SpannerException

propagateInterrupt(InterruptedException e)

public static SpannerException propagateInterrupt(InterruptedException e)
Parameter
Name Description
e InterruptedException
Returns
Type Description
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 TimeoutException
Returns
Type Description
SpannerException

Constructors

SpannerExceptionFactory()

public SpannerExceptionFactory()