Boost logo

Boost :

Subject: Re: [boost] [system][filesystem v3] Question about error_code arguments
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-27 09:44:32

Peter Foelsche wrote:
> "Beman Dawes" <bdawes_at_[hidden]> wrote in message
> >A POSIX sub-group is looking at C++ bindings for POSIX.
> >
> > They are talking about a filesystem library binding at least loosely
> > based on Boost.System, Boost.Filesystem, and C++ TR2.
> >
> > In looking at
> >,
> > "Library Support for Hybrid Error Handling (Rev 2)", they are
> > concerned about specifying hybrid error handling like this:
> What is the sense of a C++ interface, which does not throw on error?

Others noted embedded environments -- very important today -- but let's look at a broader case. Throwing an exception is extremely expensive for many reasons. Some applications encounter errors regularly and often due to the nature of their environment or context. Such applications, if errors were reported using exceptions, would have high or widely varying latencies and generally sluggish performance. If errors are relatively infrequent, then the cleanliness of writing code without error checking at every turn, and the zero or near zero overhead of exception handling code when no exceptions are raised, means using exceptions is nearly ideal. Eventually, however, there's a threshhold at which the frequency of exceptions, given the cost to throw them when they do occur, overwhelms the processing time. In that case, exceptions are a problem, not the solution.

> I think meanwhile (this is 2009) we should be over the "I
> hate C++ Exception Handling" thinking.

Perhaps there's room for other opinions on the use of exceptions now that we've moved beyond that phase and the "Exceptions are always the error handling scheme of choice in C++" phase?

This error_code scheme allows one to choose whether to get an exception or not. Thus, one chooses when the overhead of throwing exceptions is acceptable and when not. Surely that's not controversial.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

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, gregod at, cpdaniel at, john at