User Tools

Site Tools


c_-_c_exception_handling:bad_alloc_exceptions

C - C++ Exception Handling - bad_alloc Exceptions

#include <iostream>
using std::cout;
using std::bad_alloc;                  
 
int main()
{
  int* p[10];
 
  try 
  {
    for ( int i = 0; i < 10; i++ ) 
    {
      p[ i ] = new int[2];
      cout << "\nAllocated successfully";
    }
  }
  catch ( bad_alloc &memoryAllocationException )
  {
    cout << "Bad allocation " << memoryAllocationException.what() ;
  }
 
  return 0;
}
c_-_c_exception_handling/bad_alloc_exceptions.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki