Subject: Re: [boost] [system][filesystem v3] Question abouterror_codearguments
From: Gottlob Frege (gottlobfrege_at_[hidden])
Date: 2009-11-02 12:58:49
On Sun, Nov 1, 2009 at 6:03 PM, Domagoj Saric <dsaritz_at_[hidden]> wrote:
> "Gottlob Frege" <gottlobfrege_at_[hidden]> wrote in message
>> On Wed, Oct 28, 2009 at 6:46 PM, Domagoj Saric <dsaritz_at_[hidden]> wrote:
>>> i mentioned the latter 'issue' already in the first post...
>>> generally both points seem to me like non-issues because they cannot become
>>> issues unintentionally...
>>> both can come into play _only_ if the user converts the temporary return
>>> into a local scoped object/variable...which, as far as i know, you cannot do
>>> 'by accident'/unintentionally...you have to be verbose about it...(although,
>>> ironically the new auto makes it easier for you to do "the wrong
>>> still not easy enough that you can do it by a 'non conscious mistake')...
>> bool diff(file srcA, file srcB, file output)
>> // get our files ready...
>> error_code srcA_err = file_open(srcA);
>> error_code srcB_err = file_open(srcB);
>> error_code out_err = file_open(output);
>> if (srcA_err || srcB_err || out_err) // check for errors
>> return false;
>> // do the diff...
>> return true;
> true...a good "find" ;)
> sure we could argue that this is "non-idiomatic" usage...but still, as you
> said, it is not "completely unreasonable" so it should also work correctly...
> there are two ways we could achieve this:
> ...one is to "smarten" the do_throw() function (i wrote about in other posts)
> to first do the "if( !std::uncaught_exception() )" check before doing the
> actual throw (this is, imho, safe and "non-evil" which i shall argue in a
> response to emil)...
bool copy(file dest, file src)
error_code errSrc = open(src);
error_code errDst = create(dest);
if (errSrc || errDst)
In this case, we are not throwing during exception unwinding, but if
errSrc is true, errDst is NOT checked, and thus throws. Should it?
I think, at best, a smart_err_code should just assert() in debug only.
ie check to make sure errors are being checked -> ie check for
As for throwing or not, lean towards throwing, supply both when there
is good reason.
I think throwing needs to become more common, particularly with
multi-threading, because you can't necessarily check pre-conditions
anymore - the preconditions might not last long enough for the
function call. Even for file functions:
if (!exists(file)) // check precondition
create(file); // yet this throws "already exists"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk