Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] Throwing an exception on timeout
From: Igor R (boost.lists_at_[hidden])
Date: 2010-01-24 12:43:08


> const boost::function<void(const error_code &)>
> SerialInterface::ON_TIMEOUT(if_then(_1 != error::operation_aborted,
> throw_exception(bind(constructor<
>         SerialInterfaceTimeoutException> ()))));
> // ...
> void SerialInterface::read(void *buf, size_t size)
> throw(SerialInterfaceTimeoutException) {
>     charTimeout.expires_from_now(maxCharDelay);
>     charTimeout.async_wait(ON_TIMEOUT);
> // ...
>
> If a timeout occurs, the exception is thrown as expected. However, it is not
> handed any further from read, but instead the program terminates with a
> message concerning the exception. Is there any method having a throw()
> constraint in this async_wait chain?

Your ON_TIMEOUT() function is called from io_service::run().
io_service::run() does not handle your exceptions, so the exception is
unhandled and the thread is aborted.

By the way, use exception specifications carefully:
http://www.gotw.ca/gotw/082.htm


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