private static StatusRuntimeException toStatusRuntimeException(Throwable t) {
    Throwable cause = checkNotNull(t, "t");
    while (cause != null) {
      // If we have an embedded status, use it and replace the cause
      if (cause instanceof StatusException) {
        StatusException se = (StatusException) cause;
        return new StatusRuntimeException(se.getStatus(), se.getTrailers());
      } else if (cause instanceof StatusRuntimeException) {
        StatusRuntimeException se = (StatusRuntimeException) cause;
        return new StatusRuntimeException(se.getStatus(), se.getTrailers());
      }
      cause = cause.getCause();
    }
    return Status.UNKNOWN.withDescription("unexpected exception").withCause(t)
        .asRuntimeException();
  }
private static StatusRuntimeException toStatusRuntimeException ( Throwable t ) { Throwable cause = checkNotNull ( t , "t" ) ; while ( cause != null ) { if ( cause instanceof StatusException ) { StatusException se = ( StatusException ) cause ; return new StatusRuntimeException ( se . getStatus ( ) , se . getTrailers ( ) ) ; } else if ( cause instanceof StatusRuntimeException ) { StatusRuntimeException se = ( StatusRuntimeException ) cause ; return new StatusRuntimeException ( se . getStatus ( ) , se . getTrailers ( ) ) ; } cause = cause . getCause ( ) ; } return Status . UNKNOWN . withDescription ( "unexpected exception" ) . withCause ( t ) . asRuntimeException ( ) ; }
Wraps the given {@link Throwable} in a {@link StatusRuntimeException}. If it contains an
embedded {@link StatusException} or {@link StatusRuntimeException}, the returned exception will
contain the embedded trailers and status, with the given exception as the cause. Otherwise, an
exception will be generated from an {@link Status#UNKNOWN} status.