bad_alloc in C++ Last Updated : 27 Feb, 2018 Comments Improve Suggest changes Like Article Like Report Prerequisite : Exceptions in C++ Standard C++ contains several built-in exception classes. The most commonly used is bad_alloc, which is thrown if an error occurs when attempting to allocate memory with new. This class is derived from exception. To make use of bad_alloc, one should set up the appropriate try and catch blocks. Here’s a short example, that shows how it’s used : C++ // CPP code for bad_alloc #include <iostream> #include <new> // Driver code int main () { try { int* gfg_array = new int[100000000]; } catch (std::bad_alloc & ba) { std::cerr << "bad_alloc caught: " << ba.what(); } return 0; } RunTime error : bad_alloc caught: std::bad_alloc Comment More infoAdvertise with us Next Article bad_alloc in C++ B bansal_rtk_ Follow Improve Article Tags : Misc C++ cpp-exception Practice Tags : CPPMisc Similar Reads get_allocator() in C++ In STL, containers can change size dynamically. Allocator is an object that is responsible for dynamic memory allocation/deallocation. get_allocator() is used to allocate memory chunks of memory. It returns a copy of the allocator object associated with the container. It is defined in vector, map, l 4 min read map get_allocator in C++ STL map::get_allocator() is a built in function in C++ STL which is used to get allocator of container map. Syntax: Allocator_type get_allocator() Parameters: This function does not accept any parameter. Return value: Returns an allocator associated with map. Below programs explains clearly the map::get 1 min read set get_allocator() in C++ STL The set::get_allocator() in C++ STL is an in-built function which returns the copy of the allocator object associated with the set. Syntax: mulset.get_allocator(); Parameters: This function does not accept any parameters. Return Value: This function returns the allocator associated with the set. Tim 2 min read list get_allocator in C++ STL list::get_allocator() is an inbuilt in function in C++ STL which is used to get allocator of container list. Syntax: Allocator_type get_allocator() Parameters: This function does not except any parameter. Return value: Returns an allocator associated with list. Below programs explains clearly the li 2 min read deque get_allocator in C++ STL deque::get_allocator() is a built in function in C++ STL which is used to get allocator of container deque. Syntax: Allocator_type get_allocator() Parameters: This function does not accept any parameter. Return value: Returns an allocator associated with deque. Below programs illustrate the working 2 min read Like