code: private static void safeFormatTo(Formattable value, StringBuilder out, FormatOptions options) {
      // Only care about 3 specific flags for Formattable.
      int formatFlags = options.getFlags() & (FLAG_LEFT_ALIGN | FLAG_UPPER_CASE | FLAG_SHOW_ALT_FORM);
      if (formatFlags != 0) {
        // TODO: Maybe re-order the options flags to make this step easier or use a lookup table.
        // Note that reordering flags would require a rethink of how they are parsed.
        formatFlags = ((formatFlags & FLAG_LEFT_ALIGN) != 0 ? FormattableFlags.LEFT_JUSTIFY : 0)
            | ((formatFlags & FLAG_UPPER_CASE) != 0 ? FormattableFlags.UPPERCASE : 0)
            | ((formatFlags & FLAG_SHOW_ALT_FORM) != 0 ? FormattableFlags.ALTERNATE : 0);
      }
      // We may need to undo an arbitrary amount of appending if there is an error.
      int originalLength = out.length();
      Formatter formatter = new Formatter(out, FORMAT_LOCALE);
      try {
        value.formatTo(formatter, formatFlags, options.getWidth(), options.getPrecision());
      } catch (RuntimeException e) {
        out.setLength(originalLength);
        // We only use a StringBuilder to create the Formatter instance.
        try {
          formatter.out().append(getErrorString(value, e));
        } catch (IOException impossible) { }
      }
    }
docs: Returns a string representation of the user supplied formattable, accounting for any possible
  runtime exceptions.
  
  @param value the value to be formatted.
  @return a best-effort string representation of the given value, even if exceptions were thrown.