$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Oleg Abrosimov (beholder_at_[hidden])
Date: 2006-07-06 00:47:03
Emil Dotchevski wrote:
> Oleg,
> 
>> boost::throw_<read_error>();
>>
>> It would be clearly seen in code and understandable.
> 
> Note that the current boost::failed function template does not throw an 
> exception; it returns an unnamed temporary, which is then used in the 
> throw-expression, like this:
> 
> throw failed<foo>();
> 
> The reason is to allow exception info to be added tirectly in the 
> throw-expression:
> 
> throw failed<foo>() << info1() << info2() .... ;
> 
> I completely agree that "failed" is not a good word for this, but I couldn't 
> come up with anything better.
> 
consider one of your examples:
if( count!=fread(buffer,size,count,stream.get()) || ferror(stream.get()) )
             throw boost::failed<fread_error>() <<
                 boost::wrap_string<tag_function>("fread") <<
                 boost::wrap_errno() <<
                 boost::weak_ptr<FILE>(stream);
}
It can be rewritten as follows:
if( count!=fread(buffer,size,count,stream.get()) || ferror(stream.get()) )
             boost::throw_<fread_error>() <<
                 boost::wrap_string<tag_function>("fread") <<
                 boost::wrap_errno() <<
                 boost::weak_ptr<FILE>(stream);
}
assuming that destructor of an object returned by boost::throw_<> does 
the real throw job. (Yes, I know that exceptions in destructors are 
evil, but in this very special case it is ok IMO).
The idea behind this syntax is that temporary created by boost::throw_ 
would be destroyed after last call to 'operator <<'.
Best,
Oleg Abrosimov.