Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-11-21 10:52:38


From: "William E. Kempf" <wekempf_at_[hidden]>
>
> David Abrahams said:

[...]

> >>> std::map<char const*, std::string, compare_cstring>?
> >>
> >> This assumes that the what() strings are all unique,
> >
> > Show me another solution which doesn't rely on a similar assumption,
> > please.
>
> The problem is that the what() strings aren't enforcably unique.

True, they are not. This is exactly the problem, as I see it.

> In fact,
> in most cases they are user supplied, instead of implementation supplied.

User supplied what() strings? In most cases?

[...]

> >> // hypothetical code...
> >> try
> >> {
> >> ....
> >> }
> >> catch (const boost::exception& e)
> >> {
> >> std::string str = lookup(e.key());
> >
> > catch(std::exception& e)
> > {
> > std::string str = lookup(e.what());
> >
> >> // 'str' no contains a locale specific string with replacable value
> >> // markers, for instance:
> >> // "bad_argument '${argument}' thrown in ${function}"
> >> std::cout << e.format(str) << std::endl;
> >
> > Why go back to the exception object to do the formatting job here?

Sometimes it's indeed useful to do that. The exception object knows what
additional pieces of information it holds. The what() -> format string map
knows that, too. Sometimes it's good design to not burden the catch point
with that knowledge.

> > I think you can encode all of that stuff into the what() strings:
> >
> > "bad_argument$3$my_function\0"
>
> That might be another approach, but would require strict specification of
> what's returned from what(), and a more complex lookup/format mechanism.

Yes, you hit the nail on the head. "Strict specification of what's returned
from what()" is indeed what is needed.

> The main problem I see with this approach is that any existing code that
> expects what() to return a human readable (albiet unlocalized) string will
> now be getting a string that's not easy to decipher.

A string cannot be said to be human readable if it's not localized. Would
you consider a string in Bulgarian human-readable?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk