public static ForeignExceptionMessage toProtoForeignException(String source, Throwable t) {
    GenericExceptionMessage.Builder gemBuilder = GenericExceptionMessage.newBuilder();
    gemBuilder.setClassName(t.getClass().getName());
    if (t.getMessage() != null) {
      gemBuilder.setMessage(t.getMessage());
    }
    // set the stack trace, if there is one
    List<StackTraceElementMessage> stack = toProtoStackTraceElement(t.getStackTrace());
    if (stack != null) {
      gemBuilder.addAllTrace(stack);
    }
    GenericExceptionMessage payload = gemBuilder.build();
    ForeignExceptionMessage.Builder exception = ForeignExceptionMessage.newBuilder();
    exception.setGenericException(payload);
    if (source != null) {
      exception.setSource(source);
    }

    return exception.build();
  }
Helper to convert Exceptions and StackTraces from/to protobuf. (see ErrorHandling.proto for the
internal of the proto messages)
hbase-protocol-shaded/src/main/java/org/apache/hadoop/hbase/util/ForeignExceptionUtil.java