You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Alan Conway <ac...@redhat.com> on 2007/01/26 21:18:28 UTC

[c++] formatting exception and log messages.

I've started using boost::format
http://www.boost.org/libs/format/index.html to format exception
messages, it's a convenient and flexible way to produce more informative
parameterized messages, e.g.:

throw ConnectionException(
  (boost::format("Invalid channel number %d.") %channelId).str());

It also takes one (very small) step closer to internationalizable
messages (because it separates the message text from parameters to the
message.) 

I'd recommend anyone working in C++ to do likewise unless there's a
better suggestion out there. We still need to figure out a more serious
logging/exception message strategy but I think boost::format will have a
place in that too.

Cheers,
Alan.


Re: [c++] formatting exception and log messages.

Posted by Alan Conway <ac...@redhat.com>.
On Tue, 2007-01-30 at 00:02 +0000, John O'Hara wrote:
> Nutritious and delicious.
> 
> Did the same on a project a while back (though with macros and code
> generation, back when C++ was mainly broken).
> As a pattern, it was a pleasure to live with and stood the test of time.
> 
> Also, do you have FILE and LINE on the exceptions generated?  That's a lot
> better than an anonymous string in a log file.

Yup, THROW_QPID_ERROR adds FILE & LINE to the message. Useful indeed.

Cheers,
Alan.


Re: [c++] formatting exception and log messages.

Posted by John O'Hara <jo...@gmail.com>.
Nutritious and delicious.

Did the same on a project a while back (though with macros and code
generation, back when C++ was mainly broken).
As a pattern, it was a pleasure to live with and stood the test of time.

Also, do you have FILE and LINE on the exceptions generated?  That's a lot
better than an anonymous string in a log file.

John

On 26/01/07, Alan Conway <ac...@redhat.com> wrote:
>
> I've started using boost::format
> http://www.boost.org/libs/format/index.html to format exception
> messages, it's a convenient and flexible way to produce more informative
> parameterized messages, e.g.:
>
> throw ConnectionException(
>   (boost::format("Invalid channel number %d.") %channelId).str());
>
> It also takes one (very small) step closer to internationalizable
> messages (because it separates the message text from parameters to the
> message.)
>
> I'd recommend anyone working in C++ to do likewise unless there's a
> better suggestion out there. We still need to figure out a more serious
> logging/exception message strategy but I think boost::format will have a
> place in that too.
>
> Cheers,
> Alan.
>
>