Boost logo

Boost Users :

Subject: Re: [Boost-users] [exception, system] using boost::system::error_code with boost::exception
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2012-12-10 15:36:00


On Mon, Dec 10, 2012 at 3:37 AM, Marco Craveiro
<marco.craveiro_at_[hidden]> wrote:
> Hi boost users,
>
> I'm a very happy user of both error_code and exception, but now I
> found a new use case which is to combine them. So I'm looking for an
> example of how to add an error_code into an exception and get it all
> nicely formatted with diagnostic_information. I can see how to use
> error_info [1] but not error_code. Any pointers would be appreciated.

#include <boost/exception/info.hpp>
typedef boost::error_info<struct tag_error_code,error_code> error_code_;

With this, you can store error_code_ into any exceptions deriving from
boost::exception. You can then overload to_string() and use the
observers of boost::error_code to define how it appears in the string
returned by boost::diagnostic_information:

namespace boost { namespace system {
  std::string to_string( error_code const & ec )
  {
    return .....;
  }
} }

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