Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-12-17 10:18:39

From: "Vladimir Prus" <ghost_at_[hidden]>
> Peter Dimov wrote:
> >>I think that we also need to consider the problem of translating a
> >>filesystem_error to a localized error message.
> Seems like there is quite a few alternatives:
> 1. Perform localization at the point where exception is thrown. The
> problem there is getting the right message catalog.

This is possible, but not very flexible. The throw point must know how to
localize, and once the exception is thrown, you can no longer reformat the

> 2. Keep the format string and variable arguments in exception class.
> This is similiar, but IMO, different from the idea to specify values
> of 'what'. E.g
> class filesystem_exception {
> public:
> const string& format_string() const;
> const vector<string>& parameters() const;
> const char* what() const {
> boost::format f(format_string());
> const vector<string>& p = parameters();
> for (size_t i = 0; i < p.size(); ++i)
> f % p[i];
> // Do something tricky to return pointer
> // to f.str().c_str(), but prevent the
> // string from going out of scope.
> }
> void imbue(const locale&);
> };

This can be made to work, but there's still too much coupling for my taste.
The exception class must still know how to translate, and the user has no
control over the string. I.e. if you get a bug report that the string isn't
correct, you can't fix it.

The main problem is that I don't really know the answer. I can tell you what
doesn't work, but I don't know yet what works. :-)

Boost list run by bdawes at, gregod at, cpdaniel at, john at