9 #include <stk_util/environment/ReportHandler.hpp>
25 template<
class EXCEPTION>
26 void default_handler_req(
const char* expr,
27 const std::string& location,
28 std::ostringstream& message)
30 std::string error_msg =
"";
31 if (message.str() !=
"") {
32 error_msg = std::string(
"Error: ") + message.str() +
"\n";
36 std::string(
"Requirement( ") + expr +
" ) FAILED\n" +
41 template<
class EXCEPTION>
42 void default_handler_exc(
const char* expr,
43 const std::string& location,
44 std::ostringstream& message)
46 std::string error_msg =
"";
47 if (message.str() !=
"") {
48 error_msg = std::string(
"Error: ") + message.str() +
"\n";
51 std::string expr_msg =
"";
52 if (expr != std::string(
"")) {
53 expr_msg = std::string(
"Expr '") + expr +
"' eval'd to true, throwing.\n";
69 std::cout <<
"Message type " << type <<
": " << message << std::endl;
77 (*s_reportHandler)(message, type);
87 throw std::runtime_error(
"Cannot set report handler to NULL");
89 REH prev_reh = s_reportHandler;
90 s_reportHandler = reh;
98 const std::string & path)
100 static const char *prefix[] = {
"/src/",
"/include/",
"/Apps_",
"/stk_"};
102 for (
unsigned int i = 0; i <
sizeof(prefix)/
sizeof(prefix[0]); ++i) {
103 std::string::size_type j = path.rfind(prefix[i], path.length());
104 if (j != std::string::npos) {
105 j = path.rfind(
"/", j - 1);
106 if (j != std::string::npos)
107 return path.substr(j + 1, path.length());
116 const std::string& location,
117 std::ostringstream& message)
119 default_handler_req<std::logic_error>(expr, location, message);
123 const std::string& location,
124 std::ostringstream& message)
126 default_handler_exc<std::runtime_error>(expr, location, message);
130 const std::string& location,
131 std::ostringstream& message)
133 default_handler_exc<std::invalid_argument>(expr, location, message);
139 throw std::runtime_error(
"Cannot set assert handler to NULL");
142 s_assert_handler = handler;
150 throw std::runtime_error(
"Cannot set error handler to NULL");
153 s_error_handler = handler;
161 throw std::runtime_error(
"Cannot set invalid_arg handler to NULL");
164 s_invalid_arg_handler = handler;
170 const std::string& location,
171 std::ostringstream& message)
173 (*s_assert_handler)(expr, location, message);
177 const std::string& location,
178 std::ostringstream& message)
180 (*s_error_handler)(expr, location, message);
184 const std::string& location,
185 std::ostringstream& message)
187 (*s_invalid_arg_handler)(expr, location, message);