int* ptr = new int[10000000000000000]; // allocate too much memory if (!ptr) { throw ResourceError("Memory allocation failed"); }
std::ifstream file("non_existent.txt"); if (!file.is_open()) { throw ResourceError("Unable to open file"); }
int sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd < 0) { throw ResourceError("Failed to create socket"); }In this example, a TCP socket is attempted to be created using a call to socket(). However, the call fails, and a ResourceError exception is thrown to indicate the error. Package/library: Berkeley sockets library.