Fix Issue 11780 - RangeError in format for incomplete format specifier

I also had to rework the loop a tiny bit so as to preserve the fmt's integrity in case an exception is thrown (don't lose any previously not yet printed '%' character), as well as to have a coherent error message.