Boost logo

Boost Users :

Subject: Re: [Boost-users] Unable to catch exception using boost::asio
From: Alex Black (alex_at_[hidden])
Date: 2009-07-15 13:45:47


So when my app crashes, here is the message I see on the console: (if I
don't have a set_terminate handler installed)

terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info
_injector<boost::system::system_error> >'
  what(): Broken pipe

here is a more complete stack trace: (when I set a breakpoint in the
set_terminate handler)

EnginePrototype [C/C++ Application]
        gdb/mi (7/15/09 1:29 PM) (Suspended)
                Thread [1] (Suspended)
                Thread [2] (Suspended)
                Thread [3] (Suspended: Signal 'SIGABRT' received.
Description: Aborted.)
                        34 raise() 0x00007f5dc63b6fb5
                        33 abort() 0x00007f5dc63b8bc3
                        32 <symbol is not available> 0x00007f5dc6c5a4bb
                        31 <symbol is not available> 0x00007f5dc6c596ab
                        30 __gxx_personality_v0() 0x00007f5dc6c5a278
                        29 <symbol is not available> 0x00007f5dc6706ff3
                        28 _Unwind_Resume() 0x00007f5dc67070b8
                        27 ~ProtoBufStreamAdaptor()
/home/noirs/workspace/projectPrototype/EnginePrototype/src/web/ProtoBufS
treamAdaptor.cpp:10 0x000000000042c75d
                        26 CEngineWebServer::HandleGetNeighbors()
/home/noirs/workspace/projectPrototype/EnginePrototype/src/web/EngineWeb
Server.cpp:215 0x000000000041d350
                        25 CEngineWebServer::OnHttpRequest()
/home/noirs/workspace/projectPrototype/EnginePrototype/src/web/EngineWeb
Server.cpp:89 0x000000000041e808
                        24 CBaseWebServer::HandleHTTPRequest()
/home/noirs/workspace/projectPrototype/EnginePrototype/src/web/BaseWebSe
rver.cpp:105 0x00000000004092af
                        23 CBaseWebServer::HandleAccept()
/home/noirs/workspace/projectPrototype/EnginePrototype/src/web/BaseWebSe
rver.cpp:74 0x0000000000409aaa
                        22 boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>::operator()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/bind/mem_fn_te
mplate.hpp:274 0x000000000040eb2c
                        21
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()>::operator()<boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list1<boost::system::error_code&> >()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/bind/bind.hpp:
385 0x000000000040ed1e
                        20 boost::_bi::bind_t<void,
boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >::operator()<boost::system::error_code>()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/bind/bind_temp
late.hpp:32 0x000000000040ed92
                        19
boost::asio::detail::binder1<boost::_bi::bind_t<void,
boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code>::operator()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/bi
nd_handler.hpp:39 0x000000000040edb1
                        18
boost::asio::asio_handler_invoke<boost::asio::detail::binder1<boost::_bi
::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code> >()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/handler_i
nvoke_hook.hpp:63 0x000000000040ee4c
                        17
boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder1<b
oost::_bi::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code>,
boost::_bi::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> > >()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/ha
ndler_invoke_helpers.hpp:39 0x000000000040ee80
                        16
boost::asio::detail::asio_handler_invoke<boost::asio::detail::binder1<bo
ost::_bi::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code>,
boost::_bi::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code>()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/bi
nd_handler.hpp:72 0x000000000040eed3
                        15
boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder1<b
oost::_bi::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code>,
boost::asio::detail::binder1<boost::_bi::bind_t<void,
boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code> >()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/ha
ndler_invoke_helpers.hpp:39 0x000000000040eef2
                        14
boost::asio::detail::handler_queue::handler_wrapper<boost::asio::detail:
:binder1<boost::_bi::bind_t<void, boost::_mfi::mf2<void, CBaseWebServer,
boost::shared_ptr<boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > >,
boost::system::error_code const&>,
boost::_bi::list3<boost::_bi::value<CBaseWebServer*>,
boost::_bi::value<boost::shared_ptr<boost::asio::basic_stream_socket<boo
st::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> > > >,
boost::arg<1> (*)()> >, boost::system::error_code> >::do_call()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/ha
ndler_queue.hpp:192 0x00000000004109f4
                        13
boost::asio::detail::handler_queue::handler::invoke()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/ha
ndler_queue.hpp:39 0x000000000040a67c
                        12
boost::asio::detail::task_io_service<boost::asio::detail::epoll_reactor<
false> >::do_one()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/ta
sk_io_service.hpp:268 0x000000000041a5fd
                        11
boost::asio::detail::task_io_service<boost::asio::detail::epoll_reactor<
false> >::run()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/detail/ta
sk_io_service.hpp:103 0x000000000041a82a
                        10 boost::asio::io_service::run()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/asio/impl/io_s
ervice.ipp:58 0x000000000041a95c
                        9 CBaseWebServer::RunIoService()
/home/noirs/workspace/projectPrototype/EnginePrototype/src/web/BaseWebSe
rver.cpp:37 0x0000000000409c3c
                        8 boost::_mfi::mf0<void,
CBaseWebServer>::operator()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/bind/mem_fn_te
mplate.hpp:49 0x000000000040e7c2
                        7
boost::_bi::list1<boost::_bi::value<CBaseWebServer*>
>::operator()<boost::_mfi::mf0<void, CBaseWebServer>,
boost::_bi::list0>()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/bind/bind.hpp:
246 0x000000000040e805
                        6 boost::_bi::bind_t<void,
boost::_mfi::mf0<void, CBaseWebServer>,
boost::_bi::list1<boost::_bi::value<CBaseWebServer*> > >::operator()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/bind/bind_temp
late.hpp:20 0x000000000040e842
                        5
boost::detail::thread_data<boost::_bi::bind_t<void,
boost::_mfi::mf0<void, CBaseWebServer>,
boost::_bi::list1<boost::_bi::value<CBaseWebServer*> > > >::run()
/home/noirs/workspace/projectPrototype/boost_1_39_0/boost/thread/detail/
thread.hpp:56 0x000000000040e860
                        4 thread_proxy() 0x00000000004d6818
                        3 start_thread() 0x00007f5dc6ea73ba
                        2 clone() 0x00007f5dc6469fcd
                        1 <symbol is not available> 0x0000000000000000
        gdb (7/15/09 1:29 PM)
        
/home/noirs/workspace/projectPrototype/EnginePrototype/Debug/EngineProto
type (7/15/09 1:29 PM)

Here are some snippets from my code in that stack:

void CBaseWebServer::RunIoService()
{
        try
        {
                m_IoService.run();
        }
        catch ( ... )
        {
                cout << endl << "Unhandled exception in RunIoService" <<
endl;
        }
}

void CBaseWebServer::HandleAccept(shared_ptr<tcp::socket> pSocket, const
boost::system::error_code& error)
{
        if ( !error )
        {
                try
                {
                        HandleHTTPRequest(pSocket);

                        StartAccept();
                }
                catch ( ... )
                {
                        cout << endl << "Unhandled exception in
HandleAccept" << endl;
                }
        }
        else
        {
                cout << endl << "HandleAccept received error: " <<
error.message().c_str() << endl;
        }
}
 

> -----Original Message-----
> From: boost-users-bounces_at_[hidden]
> [mailto:boost-users-bounces_at_[hidden]] On Behalf Of
> Emil Dotchevski
> Sent: Wednesday, July 15, 2009 1:21 PM
> To: boost-users_at_[hidden]
> Subject: Re: [Boost-users] Unable to catch exception using boost::asio
>
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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