public static SpannerException newSpannerException( ErrorCode code, @Nullable String message, @Nullable Throwable cause) { return newSpannerExceptionPreformatted(code, formatMessage(code, message), cause); }
/** * Creates a new exception based on {@code cause}. If {@code cause} indicates cancellation, {@code * context} will be inspected to establish the type of cancellation. * * <p>Intended for internal library use; user code should use {@link * #newSpannerException(ErrorCode, String)} instead of this method. */ public static SpannerException newSpannerException(@Nullable Context context, Throwable cause) { if (cause instanceof SpannerException) { SpannerException e = (SpannerException) cause; return newSpannerExceptionPreformatted(e.getErrorCode(), e.getMessage(), e); } else if (cause instanceof CancellationException) { return newSpannerExceptionForCancellation(context, cause); } // Extract gRPC status. This will produce "UNKNOWN" for non-gRPC exceptions. Status status = Status.fromThrowable(cause); if (status.getCode() == Status.Code.CANCELLED) { return newSpannerExceptionForCancellation(context, cause); } return newSpannerException(ErrorCode.fromGrpcStatus(status), cause.getMessage(), cause); }
public static SpannerException newSpannerException( ErrorCode code, @Nullable String message, @Nullable Throwable cause) { return newSpannerExceptionPreformatted(code, formatMessage(code, message), cause); }
/** * Creates a new exception based on {@code cause}. If {@code cause} indicates cancellation, {@code * context} will be inspected to establish the type of cancellation. * * <p>Intended for internal library use; user code should use {@link * #newSpannerException(ErrorCode, String)} instead of this method. */ public static SpannerException newSpannerException(@Nullable Context context, Throwable cause) { if (cause instanceof SpannerException) { SpannerException e = (SpannerException) cause; return newSpannerExceptionPreformatted(e.getErrorCode(), e.getMessage(), e); } else if (cause instanceof CancellationException) { return newSpannerExceptionForCancellation(context, cause); } // Extract gRPC status. This will produce "UNKNOWN" for non-gRPC exceptions. Status status = Status.fromThrowable(cause); if (status.getCode() == Status.Code.CANCELLED) { return newSpannerExceptionForCancellation(context, cause); } return newSpannerException(ErrorCode.fromGrpcStatus(status), cause.getMessage(), cause); }