mercredi 5 juin 2019

Testing bad_alloc catch for self-proof

Given the following code:

try{
    //some code that allocates new memory...
}
catch(std::bad_alloc b){
    std::cout << "Could not allocate memory." << std::endl;
}

Is there a feasible way to prove (mainly to myself) that this code will properly catch a bad allocation error? I tried filling all of the memory on my computer, but the console application terminated with -1073741819 before throwing the error.

Aucun commentaire:

Enregistrer un commentaire