new with exception with Microsoft
- by wsd
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.