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);
ErrorHandler set_assert_handler(ErrorHandler handler)
void handle_error(const char *expr, const std::string &location, std::ostringstream &message)
void(* ErrorHandler)(const char *expr, const std::string &location, std::ostringstream &message)
ErrorHandler defines the signature of functions that can be used to handle errors. expr is the expression of the failing error-check, location is a raw code location (something like file:line, no prose), and message is the error message.
ErrorHandler set_error_handler(ErrorHandler handler)
void handle_invalid_arg(const char *expr, const std::string &location, std::ostringstream &message)
void report(const char *message, int type)
Function report calls the current exception reporter to report the message in x.
void default_error_handler(const char *expr, const std::string &location, std::ostringstream &message)
void default_invalid_arg_handler(const char *expr, const std::string &location, std::ostringstream &message)
void(* REH)(const char *message, int type)
Type definition REH is a pointer to a function of type void that takes a const std::exception referen...
void default_assert_handler(const char *expr, const std::string &location, std::ostringstream &message)
void handle_assert(const char *expr, const std::string &location, std::ostringstream &message)
REH set_report_handler(REH reh)
Function set_report_handler sets the exception report function to be called when an report_exception(...
void default_report_handler(const char *message, int type)
Function default_report_handler is the default error reporter for sierra exceptions. Note that it is implemented in Fmwk_sierra.C so that it can participate.
std::string source_relative_path(const std::string &path)
Function source_relative_path strips everything through "/src/", "/include/", "/App_", or "/stk_" so that error message output doesn't mention names.
ErrorHandler set_invalid_arg_handler(ErrorHandler handler)