14 #ifndef STXXL_COMMON_ERROR_HANDLING_HEADER
15 #define STXXL_COMMON_ERROR_HANDLING_HEADER
32 #define STXXL_PRETTY_FUNCTION_NAME __FUNCTION__
34 #define STXXL_PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__
40 #define STXXL_THROW2(exception_type, location, error_message) \
42 std::ostringstream msg; \
43 msg << "Error in " << location << " : " << error_message; \
44 throw exception_type(msg.str()); \
48 #define STXXL_THROW(exception_type, error_message) \
49 STXXL_THROW2(exception_type, \
50 STXXL_PRETTY_FUNCTION_NAME, \
54 #define STXXL_THROW_ERRNO2(exception_type, error_message, errno_value) \
55 STXXL_THROW2(exception_type, \
56 STXXL_PRETTY_FUNCTION_NAME, \
57 error_message << " : " << strerror(errno_value))
60 #define STXXL_THROW_ERRNO(exception_type, error_message) \
61 STXXL_THROW_ERRNO2(exception_type, error_message, errno)
64 #define STXXL_THROW_INVALID_ARGUMENT(error_message) \
65 STXXL_THROW2(std::invalid_argument, \
66 STXXL_PRETTY_FUNCTION_NAME, \
70 #define STXXL_THROW_UNREACHABLE() \
71 STXXL_THROW2(stxxl::unreachable, \
72 "file " << __FILE__ << ", line " << __LINE__, \
73 "this code should never be reachable")
78 #define STXXL_THROW_IF(expr, exception_type, error_message) \
81 STXXL_THROW(exception_type, error_message); \
86 #define STXXL_THROW_NE_0(expr, exception_type, error_message) \
87 STXXL_THROW_IF((expr) != 0, exception_type, error_message)
90 #define STXXL_THROW_EQ_0(expr, exception_type, error_message) \
91 STXXL_THROW_IF((expr) == 0, exception_type, error_message)
94 #define STXXL_THROW_LT_0(expr, exception_type, error_message) \
95 STXXL_THROW_IF((expr) < 0, exception_type, error_message)
100 #define STXXL_THROW_ERRNO_IF(expr, exception_type, error_message) \
103 STXXL_THROW_ERRNO(exception_type, error_message); \
108 #define STXXL_THROW_ERRNO_NE_0(expr, exception_type, error_message) \
109 STXXL_THROW_ERRNO_IF((expr) != 0, exception_type, error_message)
112 #define STXXL_THROW_ERRNO_EQ_0(expr, exception_type, error_message) \
113 STXXL_THROW_ERRNO_IF((expr) == 0, exception_type, error_message)
116 #define STXXL_THROW_ERRNO_LT_0(expr, exception_type, error_message) \
117 STXXL_THROW_ERRNO_IF((expr) < 0, exception_type, error_message)
122 #define STXXL_CHECK_PTHREAD_CALL(expr) \
126 STXXL_THROW_ERRNO2(stxxl::resource_error, #expr, res); \
132 #if STXXL_WINDOWS || defined(__MINGW32__)
135 #define STXXL_THROW_WIN_LASTERROR(exception_type, error_message) \
138 DWORD dw = GetLastError(); \
140 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, \
142 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
145 std::ostringstream msg; \
146 msg << "Error in " << STXXL_PRETTY_FUNCTION_NAME \
147 << " : " << error_message \
148 << " : error code " << dw << " : " << ((char*)lpMsgBuf); \
149 LocalFree(lpMsgBuf); \
150 throw exception_type(msg.str()); \
159 #endif // !STXXL_COMMON_ERROR_HANDLING_HEADER
#define STXXL_BEGIN_NAMESPACE
#define STXXL_END_NAMESPACE