VOOZH about

URL: https://www.geeksforgeeks.org/cpp/bad_alloc-in-cpp/

⇱ bad_alloc in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

bad_alloc in C++

Last Updated : 27 Feb, 2018
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 : RunTime error :
bad_alloc caught: std::bad_alloc
Comment
Article Tags: