I am trying to catch all the unhandled exceptions in my application, so I can save the log file when they occur. This is a 64-bit Windows application compiled using Visual Studio 2013, written in C ++. For testing, I use the default C ++ Win32 project generated by VS.
I am catching all exceptions by registering a handler using SetUnhandledExceptionFilter. This works great for / most / cases, but not for everyone. With the exception of all throw () - n exceptions and most hardware exceptions, such as floating point or access violations. Code that does not start the handler:
std::vector<int> foo(5, 0); for (auto& f : foo) foo.erase(foo.begin() + 1);
Instead, I just get a standard dialog box with a crash, without calling the calling exception handler. If I run it in Visual Studio with a debugger attached, it correctly reports an access violation exception. Other types of access violations also trigger the handler:
float* ptr = nullptr; float value = *ptr;
The code above starts the exception handler.
I tried using the try / catch or catching SIGSEGV signal, but none of them start with the first example. interrupt / termination signals are not called. In short, I am in no way notified when an accident occurs.
I want to know if there is a way to get some kind of notification in my application before it crashes due to an access violation caused by the first example? Since VS seems able to detect this, I assume there is a way.
EDIT: I just want it to be clear that I'm running the code in release mode, and the error in the first example is not caused by an error checking the iterator out of bounds in debug mode.
EDIT2: I included the simplest example that I can come up with with the win32 console application. See here: http://pastebin.com/8L1SN5PQ
Be sure to run it in release mode without a debugger attached.