new with exception with Microsoft

Posted by wsd on Stack Overflow See other posts from Stack Overflow or by wsd
Published on 2010-03-12T21:13:48Z Indexed on 2010/03/12 21:17 UTC
Read the original article Hit count: 213

Filed under:
|
|
|

As I'm coding for both Windows and Linux, I have a whole host of problems. Microsoft Visual C++ has no stdint header, but for that I wrote my own.

Now I found out that MS C++'s new operator does not throw an exception, so I want to fix this a quickly as possible. I know I can define a Macro with Parameters in Parenthesis, can I define a macro that replaces

MyClass x = new MyClass();

with

#ifdef MSC_VER
if(!(MyClass x = new MyClass())
{
    throw new std::bad_alloc();
}
#else
MyClass x = new MyClass();
#endif

(or something equivalent), AND works in BOTH MS C++ and G++ ?

Or alternatively if that is not possible, a batch file to run over the Code to do this? I have become rather dependent on this exception being thrown.

© Stack Overflow or respective owner

Related posts about c++

Related posts about Microsoft