10 #ifndef __PION_ERROR_HEADER__ 11 #define __PION_ERROR_HEADER__ 16 #include <boost/version.hpp> 17 #include <boost/throw_exception.hpp> 18 #include <boost/exception/exception.hpp> 19 #include <boost/exception/info.hpp> 20 #include <boost/exception/error_info.hpp> 21 #include <boost/exception/get_error_info.hpp> 22 #if BOOST_VERSION >= 104700 23 #include <boost/units/io.hpp> 25 #include <pion/config.hpp> 35 :
public virtual std::exception,
public virtual boost::exception
39 exception(
const std::string& msg) : m_what_msg(msg) {}
40 exception(
const char *
const msg) : m_what_msg(msg) {}
42 virtual const char* what()
const throw() {
43 if (m_what_msg.empty()) update_what_msg();
44 return m_what_msg.c_str();
47 inline void set_what_msg(
const char *
const msg = NULL,
const std::string *
const arg1 = NULL,
const std::string *
const arg2 = NULL,
const std::string *
const arg3 = NULL)
const {
48 std::ostringstream tmp;
49 #if BOOST_VERSION >= 104700 50 tmp << ( msg ? msg : boost::units::detail::demangle(BOOST_EXCEPTION_DYNAMIC_TYPEID(*this).type_->name()) );
52 tmp << ( msg ? msg : boost::units::detail::demangle(BOOST_EXCEPTION_DYNAMIC_TYPEID(*this).type_.name()) );
54 if (arg1 || arg2 || arg3) tmp <<
':';
55 if (arg1) tmp <<
' ' << *arg1;
56 if (arg2) tmp <<
' ' << *arg2;
57 if (arg3) tmp <<
' ' << *arg3;
58 m_what_msg = tmp.str();
60 virtual void update_what_msg()
const { set_what_msg(); }
61 mutable std::string m_what_msg;
72 static inline std::string
73 diagnostic_information( T
const & e )
75 boost::exception
const *
const be =
dynamic_cast<const boost::exception*
>(&e);
76 std::exception
const *
const se =
dynamic_cast<const std::exception*
>(&e);
77 std::ostringstream tmp;
81 #if BOOST_VERSION >= 104700 82 tmp << boost::units::detail::demangle(BOOST_EXCEPTION_DYNAMIC_TYPEID(e).type_->name());
84 tmp << boost::units::detail::demangle(BOOST_EXCEPTION_DYNAMIC_TYPEID(e).type_.name());
90 char const *
const * f=boost::get_error_info<boost::throw_file>(*be);
93 if (
int const * l=boost::get_error_info<boost::throw_line>(*be))
109 typedef boost::error_info<struct errinfo_arg_name_,std::string> errinfo_message;
112 typedef boost::error_info<struct errinfo_arg_name_,std::string> errinfo_arg_name;
115 typedef boost::error_info<struct errinfo_file_name_,std::string> errinfo_file_name;
118 typedef boost::error_info<struct errinfo_dir_name_,std::string> errinfo_dir_name;
121 typedef boost::error_info<struct errinfo_plugin_name_,std::string> errinfo_plugin_name;
124 typedef boost::error_info<struct errinfo_dir_name_,std::string> errinfo_symbol_name;
133 virtual void update_what_msg()
const {
134 set_what_msg(
"bad argument", boost::get_error_info<errinfo_arg_name>(*
this));
140 virtual void update_what_msg()
const {
141 set_what_msg(
"config parser error", boost::get_error_info<errinfo_file_name>(*
this));
147 virtual void update_what_msg()
const {
148 set_what_msg(
"unable to open file", boost::get_error_info<errinfo_file_name>(*
this));
154 virtual void update_what_msg()
const {
155 set_what_msg(
"unable to open plugin", boost::get_error_info<errinfo_plugin_name>(*
this));
161 virtual void update_what_msg()
const {
162 set_what_msg(
"unable to read file", boost::get_error_info<errinfo_file_name>(*
this));
168 virtual void update_what_msg()
const {
169 set_what_msg(
"file not found", boost::get_error_info<errinfo_file_name>(*
this));
175 virtual void update_what_msg()
const {
176 set_what_msg(
"directory not found", boost::get_error_info<errinfo_dir_name>(*
this));
182 virtual void update_what_msg()
const {
183 set_what_msg(
"plugin not found", boost::get_error_info<errinfo_plugin_name>(*
this));
189 virtual void update_what_msg()
const {
190 set_what_msg(
"duplicate plugin", boost::get_error_info<errinfo_plugin_name>(*
this));
196 virtual void update_what_msg()
const {
197 set_what_msg(
"missing plugin symbol", boost::get_error_info<errinfo_symbol_name>(*
this));
203 virtual void update_what_msg()
const {
204 set_what_msg(
"plugin has undefined state");
210 virtual void update_what_msg()
const {
211 set_what_msg(
"bad password hash");
exception thrown if we are unable to open a plugin
exception thrown if a plugin is missing a required symbol
exception thrown if a required directory is not found
exception thrown if we try to add or load a duplicate plugin
exception thrown if a plugin has an undefined state
exception thrown if a file is not found
exception thrown if we failed to open a file
exception thrown if a plugin cannot be found
exception thrown if a bad password hash is provided
exception thrown if we failed to read data from a file
exception thrown for an invalid configuration argument or option
exception thrown if there is an error parsing a configuration file