can anyone please tell me how to catch out of memory exception?
for ex.
try
{
while(true)
{
int i = new int;
}
}
catch( ? <---
You should catch an object of type std::bad_alloc.
Alternatively, you can also use a nothrow verison of new as:
int *pi = new (nothrow) int[N];
if(pi == NULL)
{
std::cout << "Could not allocate memory" << std::endl;
}
When you use this, no exception is thrown if the new fails. Instead,it simply returns NULL which you check before proceeding further.