27 #ifndef SHORE_PROGRAM_UNCAUGHT_HANDLER_HPP__
28 #define SHORE_PROGRAM_UNCAUGHT_HANDLER_HPP__
36 #include <boost/filesystem.hpp>
37 #include <boost/version.hpp>
53 STATUS_ERR_FILESYSTEM,
68 bool m_rethrow_exceptions;
76 void set_rethrow_exceptions(
const bool b);
84 void set_file(
const std::string &fn);
90 void add_file(
const std::string &fn);
95 template<
typename Func>
96 Status operator()(Func func)
109 m_status=STATUS_ERR_USAGE;
116 #if (BOOST_VERSION / 100) < 1035
117 catch(
const boost::filesystem::basic_filesystem_error<boost::filesystem::path> &e)
119 m_status=STATUS_ERR_FILESYSTEM;
121 (*m_os)<<m_name<<
": filesystem error --- "<<e.what()
124 (*m_os)<<
"error code "<<e.system_error()
125 <<
": "<<std::strerror(e.system_error());
127 if(!e.path1().empty())
129 (*m_os)<<
" {\""<<e.path1();
130 if(!e.path2().empty())
132 (*m_os)<<
"\", \""<<e.path2();
139 if(m_rethrow_exceptions)
142 #endif // BOOST_VERSION
143 catch(
const boost::filesystem::filesystem_error& e)
145 m_status=STATUS_ERR_FILESYSTEM;
147 (*m_os)<<m_name<<
": filesystem error --- "<<e.what()
150 #if (BOOST_VERSION / 100) < 1035
152 (*m_os)<<
"error code "<<e.system_error()
153 <<
": "<<std::strerror(e.system_error())<<std::endl;
155 #else // BOOST_VERSION
158 (*m_os)<<
"error code "<<e.code().value()<<
": "
159 <<e.code().message()<<std::endl;
161 #endif // BOOST_VERSION
163 if(m_rethrow_exceptions)
166 catch(
const std::ios_base::failure& e)
168 m_status=STATUS_ERR_IO;
170 (*m_os)<<m_name<<
": read/write failure --- "<<e.what()
173 if(m_rethrow_exceptions)
176 catch(
const std::runtime_error& e)
178 m_status=STATUS_ERR_RUNTIME;
180 (*m_os)<<m_name<<
": runtime error --- "<<e.what()
183 if(m_rethrow_exceptions)
186 catch(
const std::domain_error& e)
188 m_status=STATUS_ERR_DOMAIN;
190 (*m_os)<<m_name<<
": domain error --- "<<e.what()
193 if(m_rethrow_exceptions)
196 catch(
const std::logic_error& e)
198 m_status=STATUS_ERR_LOGIC;
200 (*m_os)<<m_name<<
": logic error --- "<<e.what()
202 (*m_os)<<
"Please report this bug."<<std::endl;
204 if(m_rethrow_exceptions)
207 catch(
const std::exception& e)
209 m_status=STATUS_ERR_EXCEPTION;
211 (*m_os)<<m_name<<
": exception --- "<<e.what()<<std::endl;
213 if(m_rethrow_exceptions)
218 m_status=STATUS_ERR_ANY;
220 (*m_os)<<m_name<<
": error"<<std::endl;
222 if(m_rethrow_exceptions)
233 #endif // SHORE_PROGRAM_UNCAUGHT_HANDLER_HPP__