CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #140

What new Throws When Memory Runs Out

easyExceptions

When new cannot get the memory it was asked for, which exception does it throw, and would this handler catch it?

📄 Code

1#include <iostream>
2#include <new>
3#include <exception>
4 
5int main() {
6 try {
7 throw std::bad_alloc();
8 } catch (const std::exception&) {
9 std::cout << "memory problem caught\n";
10 }
11 return 0;
12}