Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bad_alloc identifier not recognized?

I'm getting a compiler error:

error C2061: syntax error : identifier 'bad_alloc'

I've used the chunk of code below in other projects before, with different memory allocation within the try block, without problems. I was hoping someone could explain to me why bad_alloc isn't being recognized by VS10 despite it not causing the same problem in use in other programs? Odds are I missed some minor syntactical thing, but I've spent hours trying to figure it out, and at this point I feel like I'm probably blind to the error. Thanks for the help!

try
{
    node* tbr = new node();
    return tbr;
} // End try allocation

catch(bad_alloc)
{
     throw OutOfMemoryException();
} // End catch(bad_alloc)
like image 728
acwatson421 Avatar asked Jun 01 '26 18:06

acwatson421


1 Answers

bad_alloc is defined in the header new.

#include <new>

In namespace std.

using namespace std
like image 108
Arjen Avatar answered Jun 03 '26 08:06

Arjen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!