code: 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);
      } else if (cause instanceof ApiException) {
        return fromApiException((ApiException) 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);
    }
docs: 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.