Boost logo

Boost :

From: George A. Heintzelman (georgeh_at_[hidden])
Date: 2001-07-30 15:03:50


> I am a little interested to hear what others have to say about using
> exception based failure mechanisms rather than return codes. Do you
> really need people to be putting every little socket function in a
> try/catch block in order to run safely?

No! If your functions are written exception-safe themselves, an
exception in the library will just bubble up. A possible
exception-throw does not mean it has to be handled in the immediate
surrounding scope.

> What about instances where an
> application will still want to continue running after a failure, just
> without network support. It seems to me to be simpler to just let the
> application check the return codes, rather than deal with the complexities
> of setting it's own error codes in each catch block.

No, I think this is exactly where one would want exception handling.
All the socket library knows is that it could not do what it was
requested to do -- that is, open a socket. It may well be that the user
will have something wrapping this failed call which could handle the
exception -- or maybe it needs to pass it on up to an upper-level error
handler (Failed to open document, for example), where it can proceed,
perhaps setting a flag to forbid network attempts in the future.

I think these failures are classic examples of where one SHOULD throw
exceptions.

> I also think that TCP/IP should be the basis of this design, but it
> shouldn't be the only thing included.

I agree, and I think this can be handled very nicely at the lowest
layer being discussed, in addition to that layer being able to provide
platform independence.

George Heintzelman
georgeh_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk