13 #ifndef STXXL_ERROR_HANDLING_HEADER 14 #define STXXL_ERROR_HANDLING_HEADER 20 #include <stxxl/bits/namespace.h> 21 #include <stxxl/bits/common/exceptions.h> 24 __STXXL_BEGIN_NAMESPACE
26 #define _STXXL_STRING(x) # x 29 #define STXXL_PRETTY_FUNCTION_NAME __FUNCTION__ 31 #define STXXL_PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__ 36 #define STXXL_THROW(exception_type, location, error_message) \ 38 std::ostringstream msg_; \ 39 msg_ << "Error in " << location << ": " << error_message; \ 40 throw exception_type(msg_.str()); \ 43 #define STXXL_THROW2(exception_type, error_message) \ 44 STXXL_THROW(exception_type, "function " << STXXL_PRETTY_FUNCTION_NAME, \ 45 "Info: " << error_message << " " << strerror(errno)) 47 #define STXXL_THROW_INVALID_ARGUMENT(error_message) \ 48 STXXL_THROW(std::invalid_argument, \ 49 "function " << STXXL_PRETTY_FUNCTION_NAME, \ 52 #define STXXL_THROW_UNREACHABLE() \ 53 STXXL_THROW(stxxl::unreachable, \ 54 "file: " << __FILE__ << ", line: " << __LINE__, \ 55 "must be unreachable code") 60 inline void stxxl_util_function_error(
const char * func_name,
const char * expr = 0,
const char * error = 0)
62 std::ostringstream str_;
63 str_ <<
"Error in function " << func_name <<
" " << (expr ? expr : strerror(errno));
69 #define stxxl_function_error(exception_type) \ 70 stxxl::stxxl_util_function_error<exception_type>(STXXL_PRETTY_FUNCTION_NAME) 73 inline bool helper_check_success(
bool success,
const char * func_name,
const char * expr = 0,
const char * error = 0)
76 stxxl_util_function_error<E>(func_name, expr, error);
80 template <
typename E,
typename INT>
81 inline bool helper_check_eq_0(INT res,
const char * func_name,
const char * expr,
bool res_2_strerror =
false)
83 return helper_check_success<E>(res == 0, func_name, expr, res_2_strerror ? strerror(res) : 0);
86 #define check_pthread_call(expr) \ 87 stxxl::helper_check_eq_0<stxxl::resource_error>(expr, STXXL_PRETTY_FUNCTION_NAME, _STXXL_STRING(expr), true) 89 template <
typename E,
typename INT>
90 inline bool helper_check_ge_0(INT res,
const char * func_name)
92 return helper_check_success<E>(res >= 0, func_name);
95 #define stxxl_check_ge_0(expr, exception_type) \ 96 stxxl::helper_check_ge_0<exception_type>(expr, STXXL_PRETTY_FUNCTION_NAME) 98 template <
typename E,
typename INT>
99 inline bool helper_check_ne_0(INT res,
const char * func_name)
101 return helper_check_success<E>(res != 0, func_name);
104 #define stxxl_check_ne_0(expr, exception_type) \ 105 stxxl::helper_check_ne_0<exception_type>(expr, STXXL_PRETTY_FUNCTION_NAME) 107 __STXXL_END_NAMESPACE
109 #endif // !STXXL_ERROR_HANDLING_HEADER