Subject: Re: [boost] [system][filesystem v3] Question about error_codearguments
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-29 10:56:38
Scott McMurray wrote:
> 2009/10/29 Stewart, Robert <Robert.Stewart_at_[hidden]>:
> > ~error_code() could test for a pending exception before
> > throwing an exception. If there is a pending exception, that
> > means the stack is being unwound and the error_code shouldn't
> > aggravate the situation by throwing its own. Otherwise, it
> > can throw in its destructor, right? Given that the caller
> > expressly asked for the function to throw no exceptions but
> > populate an error_code, it isn't too much to expect that
> > caller to check for an error, even when the error is to be
> > ignored. (Indeed, error_code could provide a constructor
> > argument or member function indicating that the caller wishes
> > to ignore the error.)
> "Unfortunately, I do not know of any good and safe use for
> std::uncaught_exception. My advice: Don't use it."
> ~ http://www.gotw.ca/gotw/047.htm
Yes, I was aware of those issues. However, the point of the exception here is to flag that the client failed to do what should have been done: check for errors. To be helpful, the original error information is passed along, but that is most helpful, in my mind, to help identify the place where the failure to check occurred. That the exception won't be thrown in certain contexts doesn't mean it isn't useful in the rest. One might argue that clients will try to rely on the exception since it contains the error information, so perhaps not transmitting that information with the "unhandled error" exception is wiser.
I briefly considered mentioning asserting in my last post, but chose not to just to focus on the other ideas. To throwing an exception when there isn't a pending exception, we can assert, in debug builds anyway, when the error isn't checked. Thus, the developer should get an assertion failure pointing to the error_code that wasn't checked. If the assertion is disabled (non-debug build, say), the application will get an exception in most circumstances. The point is to make it unwise to fail to check an error_code for errors.
Add to that the use of overloads to distinguish throwing from non-throwing (but error_code populating) functions and its a pretty decent mechanism, don't you think?
Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP http://www.sig.com
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk