|
Boost : |
From: Emil Dotchevski (emil_at_[hidden])
Date: 2008-07-03 15:21:58
You could do:
struct file_open_info
{
std::string file_name;
int errno_;
file_open_info( std::string const & file_name, int errno_ ):
file_name(file_name),errno_(errno_)
{
}
};
typedef boost::error_info<struct tag_missing_log_file,file_open_info>
missing_log_file;
typedef boost::error_info<struct tag_missing_cfg_file,file_open_info>
missing_cfg_file;
struct my_error: std::exception, boost::exception { };
my_error error;
....
if( no-log-file )
error << missing_log_file(file_open_info("foo.log",errno));
....
if( no-cfg-file )
error << missing_cfg_file(file_open_info("foo.cfg",errno));
.... <later>
throw error;
In addition, you can catch an active my_error exception as
boost::exception (meaning, you don't care if it's my_error or some
other boost::exception), add more data, and rethrow:
catch( boost::exception & error )
{
error << whatever(....);
throw;
}
Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode
On Thu, Jul 3, 2008 at 10:12 AM, Tom Brinkman <reportbase_at_[hidden]> wrote:
> Is there a way to delay throwing an exception?
>
> Reason #1
> Sometimes, one may want to accumulate all error conditions, but ignore
> them unless a fatal error condition occurs. These non-throw errors
> might be considered warnings, but useful to report if a later fatal
> error conditions occurs.
>
> Reason #2
> It may be preferable to report all errors at once and not have a throw
> after each error. Waiting to throw the error may provide for more
> complete error statements.
>
>
> Example:
>
> my_error error;
>
> error << error1("aaaaa");
> error << error2("bbbbbb");
>
> .... <later>
>
> throw error << error3("cccc");
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk