|
Boost : |
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2007-10-03 13:28:37
The concurrent messages at present about Boost.Exceptions and
Boost.Logging make me wonder if there should be some common ground.
In particular, if the content of an exception will mainly be used for
debugging, then the "...while frobnicating the whatsit..." information
that can be added as the exception propogates up can be the same as the
"debug: start frobinicating whatsit" and "debug: done frobnicating
whatsit" messages that the logger might record.
I am imagining something like this
frob() {
ScopedLogger l("frob"); // l constructor logs "starting frob"
do_something();
if (?) return; // l destructor logs "ending frob"
something_else();
// l destructor logs "ending frob"
}
Now, say do_something() throws an exception that says
"write(/etc/passwd): permission denied". As this propogates up, the l
destructor will be invoked. It would be great if the l destructor
could append " in frob" to the exception message. I can see how this
can be done with per-thread state; no doubt there are cases involving
exceptions-in-destructors and similar nasties to avoid.
Thinking about the implications for the proposed exception library
(since that's the one that we're currently reviewing):
- Is it possible to store more than one item of each tag type, such as
"while doing X" backtrace data?
- Thinking about my own code, practically all of my exceptions either
carry very little data and are caught by nearby code (e.g. crc_error
--> retry) or they contain text that is eventually presented to the
user or logged in an error message; in the latter case I use operator<<
to do formatted output into a stringstream in the exception. Are there
many use-cases where adding lots of extra information is useful, but
it's not better just to add it as formatted text?
Cheers, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk