Boost logo

Boost Users :

Subject: Re: [Boost-users] Unable to catch exception using boost::asio
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-07-15 13:20:45


On Wed, Jul 15, 2009 at 10:10 AM, Alex Black <alex_at_[hidden]> wrote:
> You mentioned never throwing exceptions in destructors - sounds like
> good advice, thx. Two points though:
> 1. If an exception is thrown in a destructor can it not be caught with a
> try catch( ... )?

If a destructor calls functions that may throw, it should use
catch(...) and not let exceptions propagate out of the destructor
itself. However, when writing or sending data, the user may want to
know that the operation has completed successfully. Typically, you'd
provide a separate flush function for that use case, which you'd then
call in the destructor, as in:

foo_sender::~foo_sender()
{
  try
  {
    flush();
  }
  catch(...)
  {
  }
}

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net