Go to the documentation of this file. 14 #ifndef FOXXLL_COMMON_ERROR_HANDLING_HEADER 15 #define FOXXLL_COMMON_ERROR_HANDLING_HEADER 26 #include <foxxll/config.hpp> 31 #define FOXXLL_PRETTY_FUNCTION_NAME __FUNCTION__ 33 #define FOXXLL_PRETTY_FUNCTION_NAME __PRETTY_FUNCTION__ 39 #define FOXXLL_THROW2(exception_type, location, error_message) \ 41 std::ostringstream msg; \ 42 msg << "Error in " << location << " : " << error_message; \ 43 throw exception_type(msg.str()); \ 47 #define FOXXLL_THROW(exception_type, error_message) \ 50 FOXXLL_PRETTY_FUNCTION_NAME, \ 55 #define FOXXLL_THROW_ERRNO2(exception_type, error_message, errno_value) \ 58 FOXXLL_PRETTY_FUNCTION_NAME, \ 59 error_message << " : " << strerror(errno_value) \ 63 #define FOXXLL_THROW_ERRNO(exception_type, error_message) \ 64 FOXXLL_THROW_ERRNO2(exception_type, error_message, errno) 67 #define FOXXLL_THROW_INVALID_ARGUMENT(error_message) \ 69 std::invalid_argument, \ 70 FOXXLL_PRETTY_FUNCTION_NAME, \ 75 #define FOXXLL_THROW_UNREACHABLE() \ 77 foxxll::unreachable, \ 78 "file " << __FILE__ << ", line " << __LINE__, \ 79 "this code should never be reachable" \ 85 #define FOXXLL_THROW_IF(expr, exception_type, error_message) \ 88 FOXXLL_THROW(exception_type, error_message); \ 93 #define FOXXLL_THROW_ERRNO_IF(expr, exception_type, error_message) \ 96 FOXXLL_THROW_ERRNO(exception_type, error_message); \ 101 #define FOXXLL_THROW_ERRNO_NE_0(expr, exception_type, error_message) \ 102 FOXXLL_THROW_ERRNO_IF((expr) != 0, exception_type, error_message) 104 #if FOXXLL_WINDOWS || defined(__MINGW32__) 107 #define FOXXLL_THROW_WIN_LASTERROR(exception_type, error_message) \ 110 DWORD dw = GetLastError(); \ 112 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, \ 114 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \ 118 std::ostringstream msg; \ 119 msg << "Error in " << FOXXLL_PRETTY_FUNCTION_NAME \ 120 << " : " << error_message \ 121 << " : error code " << dw << " : " << ((char*)lpMsgBuf); \ 122 LocalFree(lpMsgBuf); \ 123 throw exception_type(msg.str()); \ 130 #endif // !FOXXLL_COMMON_ERROR_HANDLING_HEADER