Re: Unhandled exception - How to turn off!




I don't use exception handling and things like failed memory allocations
(new()) failures are expected and handled internally. I tried setting
the VS2005 ide setting for C++ Exception Handling to No yet when new()
fails it throws up a screen about a run-time error. If running in the
VS2005 environment, you get

"Unhandled exception at 0x12345 in progname.exe: Microsoft C++ exception:
std::bad_alloc at memory location 0x121345"

Continue or Break. I can continue and continue and the program runs
fine.

So how to I turn off all Exception Handling so it's not used at all???

You want new to return NULL in case of failure instead of throwing?
You're now (since C++03 I think) supposed to do:

new (std::nothrow) T[N];

to get that functionality.

There are some tricks you can do to get that behavior process-wide without
editing every line of code, but you have to ask whether you want to have
code that's unmaintainable because it doesn't follow the standard.

If you decide putting std::nothrow on each allocation is too much effort,
post again and we'll see about activating the old behavior.


I found:

"If you still want the non-throwing version of new for the C Runtime
Library, link your program with nothrownew.obj. However, when you link with
nothrownew.obj, new in the Standard C++ Library will no longer function."

That took care of it.

You'd think they would have left new alone for all the existing code and had
it "new (std::throw) T[N]" instead. (or something easier to type).



.



Relevant Pages

  • Re: Unhandled exception - How to turn off!
    ... I don't use exception handling and things like failed memory allocations ... failures are expected and handled internally. ... VS2005 ide setting for C++ Exception Handling to No yet when newfails ...
    (microsoft.public.vc.language)
  • Unhandled exception - How to turn off!
    ... I don't use exception handling and things like failed memory allocations ... failures are expected and handled internally. ... VS2005 ide setting for C++ Exception Handling to No yet when newfails it ...
    (microsoft.public.vc.language)

Loading