-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetNewHandler.cpp
More file actions
46 lines (35 loc) · 1.03 KB
/
SetNewHandler.cpp
File metadata and controls
46 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* \file SetNewHandler.cpp
* \brief Set new handler function
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
void onOutOfMemory()
{
std::cout << "Memory allocation failed, terminating" << std::endl;
std::abort();
}
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::set_new_handler(onOutOfMemory);
try {
while (true) {
std::cout << "call new..." << std::endl;
new int[1000'000'000ul]();
}
}
catch (const std::bad_alloc &e) {
std::cout << STD_TRACE_VAR(e.what()) << std::endl;
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
onOutOfMemory - not called
---------------------------------------------
Killed
---------------------------------------------
#endif