#include#include #include #include #include #include void handleFailure() { std::cerr << "A standard library function failed to execute properly."; std::cerr << "Error message: " << strerror(errno) << std::endl; throw std::runtime_error("An error has occurred."); } int main() { std::set_new_handler(handleFailure); void* ptr = new int[1000000000000000000]; return 0; }
#includeIn this example, we are using GetMessageString to retrieve the message string for the last error that occurred in the Windows API. We pass the error code to FormatMessage, which formats it into a human-readable error message stored in the errorMessage variable. Both of these examples use standard C++ libraries, so the package library is the C++ standard library.#include #include int main() { DWORD errorCode = GetLastError(); TCHAR errorMessage[256]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorCode, 0, errorMessage, 256, NULL); std::cout << "Error message: " << errorMessage << std::endl; return 0; }