You can catch it like any other exception:
try { foo(); } catch (const std::bad_alloc&) { return -1; }
Quite what you can usefully do from this point is up to you, but it’s definitely feasible technically.
Related Posts:
- delete vs delete[] operators in C++
- Is “delete this” allowed in C++?
- “std::bad_alloc”: am I using too much memory?
- What is the array form of ‘delete’?
- Deleting a dynamically allocated 2D array
- malloc for struct and pointer in C
- How do malloc() and free() work?
- Deleting an object in C++
- What does ‘corrupted double-linked list’ mean
- How to solve access violation writing location error?
- Calculating Page Table Size
- Why is this vector iterator not incrementable?
- Different ways to deallocate an array – c++
- What is a segmentation fault?
- What are the -Xms and -Xmx parameters when starting JVM?
- Regular cast vs. static_cast vs. dynamic_cast
- What is an unsigned char?
- C++ std::priority_queue uses the lambda expression
- When to use reinterpret_cast?
- Expression must be a modifiable lvalue
- How to read a file line by line or a whole text file at once?
- How to print elements in a vector c++
- Split a string using C++11
- error: expected unqualified-id error: Meaning and fix? [duplicate]
- How to track down a “double free or corruption” error
- The Definitive C++ Book Guide and List
- C++ code file extension? What is the difference between .cc and .cpp
- undefined reference to `WinMain@16′
- how does the ampersand(&) sign work in c++?
- What does purpose use #ifdef and #if in C++
- How to solve munmap_chunk(): invalid pointer error in C++
- “X does not name a type” error in C++
- TranslateName() function doesn’t work on win10
- How to use the PI constant in C++
- How to concatenate two strings in C++?
- How to get current time and date in C++?
- where is the official c++ documentation
- wntdll.pdb not loaded – Can’t see the exception
- dynamic_cast and static_cast in C++
- What exactly is std::atomic?
- Separating class code into a header and cpp file
- Error while overloading operator (must be a nonstatic member function)
- C++ Fatal Error LNK1120: 1 unresolved externals
- Vector of structs initialization
- C++ deprecated conversion from string constant to ‘char*’
- How to read groups of integers from a file, line by line in C++
- Converting a vector
to string - std::string formatting like sprintf
- Sorting Characters Of A C++ String
- Sentinel while loop for C++
- How to ensure that a std::map is ordered?
- How to write C++ getters and setters
- std::out_of_range error?
- “non-standard syntax; use ‘&’ to create a pointer to member” error in Visual Studio 2015
- libpng warning: iCCP: known incorrect sRGB profile
- C++: Expression must have a constant value when declaring array inside function
- What does ‘const static’ mean in C and C++?
- How to determine if a string is a number with C++?
- C++ wait for user input
- non-standard syntax; use ‘&’ to create a pointer to member
- How to shuffle a std::vector?
- Center text in fixed-width field with stream manipulators in C++
- ctypes error: libdc1394 error: Failed to initialize libdc1394
- Understanding glm::lookAt()
- How to get current timestamp in milliseconds since 1970 just the way Java gets
- Debug vs Release in CMake
- C++ Matrix Class
- access violation reading location c++
- C++ template constructor
- PlaySound in C++ Console application?
- Creation of Dynamic Array of Dynamic Objects in C++
- Compiling simple Hello World program on OS X via command line
- Cannot open output file, permission denied
- Conflict Miss v/s Compulsory Miss
- Strange error C2131: expression did not evaluate to a constant in VC 2015
- variable-sized object may not be initialized c++
- Why I cannot cout a string?
- How do I return a char array from a function?
- c++ reading csv file
- Why do you use typedef when declaring an enum in C++?
- When to use const char * and when to use const char []
- What is wrong with using goto?
- Double pointer array in c++
- creating dynamic array of string c++
- How well is Unicode supported in C++11?
- The CXX compiler identification is unknown
- Is there a standard sign function (signum, sgn) in C/C++?
- C++ compiler error: “return type specification for constructor invalid”
- error: ISO C++ forbids in-class initialization of non-const static member
- Function call missing argument list to create pointer
- cannot specify explicit initializer for arrays
- What does ** mean in C++?
- How to determine the version of the C++ standard used by the compiler?
- How to force JavaScript to deep copy a string?
- Make / gcc cryptic error 2: how to have more information?
- REGSVR32: the module “xxxxx.dll” failed to load … dependent assembly could not be found
- Error: expression cannot be used as a function?
- What is a .h.gch file?
- MinGW .exe requires a few gcc dll’s regardless of the code?
- Converting bool to text in C++