[IPOL discuss] Software crashes

Miguel Colom colom at cmla.ens-cachan.fr
Fri May 31 11:09:17 CEST 2013


Quoting Pierre Moulon <pmoulon at gmail.com>:
> Dear Miguel,
>
> Another rigorous solution could be to use standard C++ exception checking:
>
> try
>   {
>     int* myarray= new int[10000];
>   }
>   catch (std::bad_alloc& ba)
>   {
>     std::cerr << "bad_alloc caught: " << ba.what() << '\n';
>   }

I agree. Catching a bad_alloc exception (in C++) or a null pointer  
given by malloc (in C) is really recommended.

Since the demos are restricted to use at most 1Gb of memory by the  
Software Guidelines, a bad_alloc normally is not related directly to  
an out-of-memory problem, but to memory corruption caused by prior  
operations.




More information about the discuss mailing list