24 #ifndef _EXCEPTION_HPP_ 25 #define _EXCEPTION_HPP_ 42 public:
user_error(
const std::string& what) :
std::runtime_error(what) {}
58 extern "C" __declspec(dllimport)
unsigned int __stdcall SetErrorMode(
unsigned int uMode);
62 inline std::string narrow(
const std::wstring& str)
64 std::ostringstream oss;
65 const std::ctype<wchar_t>& ctfacet = std::use_facet< std::ctype<wchar_t> >(oss.getloc());
66 for (
size_t i=0; i < str.size(); ++i)
67 oss << ctfacet.narrow(str[i], 0);
71 inline int CrtReportHook(
int reportType,
char *message,
int *returnValue)
73 if (reportType == _CRT_ERROR || reportType == _CRT_ASSERT)
74 throw std::runtime_error(message);
78 inline int CrtReportHookW(
int reportType,
wchar_t *message,
int *returnValue)
80 if (reportType == _CRT_ERROR || reportType == _CRT_ASSERT)
81 throw std::runtime_error(narrow(message));
91 SetErrorMode(SetErrorMode(0) | 0x0002);
92 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
93 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
94 _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, &CrtReportHook);
95 _CrtSetReportHookW2(_CRT_RPTHOOK_INSTALL, &CrtReportHookW);
100 _CrtSetReportHook2(_CRT_RPTHOOK_REMOVE, &CrtReportHook);
101 _CrtSetReportHookW2(_CRT_RPTHOOK_REMOVE, &CrtReportHookW);
104 static ReportHooker reportHooker;
110 #define BOOST_ENABLE_ASSERT_HANDLER 114 inline void assertion_failed(
char const * expr,
char const *
function,
char const * file,
long line)
116 std::ostringstream oss;
117 oss <<
"[" << file <<
":" << line <<
"] Assertion failed: " << expr;
118 throw std::runtime_error(oss.str());
121 inline void assertion_failed_msg(
char const * expr,
char const * msg,
char const *
function,
char const * file,
long line)
123 std::ostringstream oss;
124 oss <<
"[" << file <<
":" << line <<
"] Assertion failed: " << expr <<
" (" << msg <<
")";
125 throw std::runtime_error(oss.str());
128 #endif // !defined(NDEBUG) 131 #endif // _EXCEPTION_HPP_
user_error(const std::string &what)
void assertion_failed_msg(char const *expr, char const *msg, char const *function, char const *file, long line)
usage_exception(const std::string &usage)
void assertion_failed(char const *expr, char const *function, char const *file, long line)