Exception handling in Boost.Asio

前端 未结 1 1128
难免孤独
难免孤独 2020-12-17 20:37

Boost.Asio documentation suggests the following exception handling pattern:

boost::asio::io_service io_service;
...
for (;;)
{
  try
  {
    io_service.run()         


        
相关标签:
1条回答
  • 2020-12-17 21:17

    There is nothing wrong with the pattern recommended by Boost.Asio. What you should do is package any necessary information for handling the exception along with the exception object. If you use boost::exception (or a type derived from it) for your exception handling, you can very easily attach metadata (including session information) by creating a specialization of boost::error_info and attaching it to the exception object using operator<<. Your catch block can then extract this info with get_error_info.

    0 讨论(0)
提交回复
热议问题