Boost logo

Boost Users :

Subject: Re: [Boost-users] How to make Boost.Format fault tolerant?
From: John M. Dlugosz (mpbecey7gu_at_[hidden])
Date: 2012-02-11 02:52:16


On 2/11/2012 1:43 AM, John M. Dlugosz wrote:
>
> It seems to suppress exceptions for some things, but a format string like:
> "Funny format string: 25% off now! %z %x"
> still throws an exception "boost::bad_format_string: format-string is ill-formed"
> when exceptions(boost::io::no_error_bits) is used.
>

The example could be more enlightening…

        boost::format my_fmt(const std::string & f_string) {
            using namespace boost::io;
            format fmter(f_string);
            fmter.exceptions( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ));
            return fmter;
        }

doesn't work for errors in the format string itself.

It would be better illustrated along the lines of:

        boost::format my_fmt(const std::string & f_string) {
            using namespace boost::io;
            format fmter; // don't give it the string until after the exceptions are set
            fmter.exceptions( whatever );
            fmter.parse (f_string);
            return fmter;
        }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net