Boost logo

Boost :

From: Gerhard Wesp (gwesp_at_[hidden])
Date: 2006-08-24 04:59:04


On Wed, Aug 23, 2006 at 11:20:20AM -0700, Emil Dotchevski wrote:
> If I understand you correctly, you are storing a user message in the
> exception when you throw it, and then use std::exception::what() to retrieve
> it, right? This approach is problematic for several reasons, most notably

Indeed. I don't localize error messages, in fact I've never met a
program that correctly and completely implemented localized error
messages. I guess it's because the problem doesn't scale so well.

> because the user message has to be localized, but also because different
> programs may need to output different messages in response to the same
> exception thrown by a shared library.

Hmmm... Can you give an example? I try to restrict the what() string
to be indepentent of library usage and add more information higher up
the call stack, possibly re-throwing afterwards. E.g., a file object
constructor might throw "couldn't open <filename>: <error>" and then,
it's caller might prepend some more context information to make that
either
  "Reading configuration file: couldn't open <filename>: <error>"
or
  "Parsing data file: couldn't open <filename>: <error>"

This works quite well, but yeah, maybe there are situations where string
concatenation is too simplistic.

Regards
-Gerhard


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