|
Boost Users : |
Subject: Re: [Boost-users] Simple use case for boost exceptions
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-12-04 17:27:22
On Thu, Dec 4, 2008 at 1:20 PM, Yang Zhang <yanghatespam_at_[hidden]> wrote:
> With boost::exception, can I simply construct an exception with a custom
> what() message (without subclassing exception)? Thanks.
> --
> Yang Zhang
> http://www.mit.edu/~y_z/
No, you can't.
When throwing exceptions, you shouldn't be concerned with formatting a
friendly user message, only with making sure that the exception
contains enough information for such a message to be composed at the
catch point. The primary boost::exception design goal is to streamline
this process of transporting information to the catch point: see
http://www.boost.org/doc/libs/1_37_0/libs/exception/doc/tutorial_transporting_data.html.
Also, instead of formatting a custom user-friendly message, you can
use boost::diagnostic_information() to get a string that contains all
the information carried by a boost::exception. See
http://www.boost.org/doc/libs/1_37_0/libs/exception/doc/tutorial_diagnostic_information.html.
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net