I added a mini-core-dump function (via __try / __ except and MiniDumpWriteDump ()) to the Windows build of my Qt application, so that if / when my application ever works, a .dmp file will be written to disk for me to look and debug later.
This works very well, but for testing, I would like to have a well-known and reliable method to crash my program. For example, the graphical interface may have a “crash now” button, and when the user clicks on it, this will lead to an unintentional crash of the application.
One way to do this, of course, is:
int * badPointer = NULL; *badPointer = 666;
And it works for me, but I don’t like this approach because it relies on undefined behavior - in particular, the C ++ standard does not require the above code to crash, so it’s possible (from the point of view of a lawyer language), that some future version of the compiler will not work when the above code is executed.
As a more “official” approach, I tried this:
abort();
... which terminates the program, but this does not cause Windows Structured Exception to run the MiniCrashDump handler, so the .dmp file is not written.
My question is, is there an “Official Right Way” for breaking down my program? I see that the Windows API has a RaiseException () function that I could call, but I'm not sure what the correct arguments should be. Is this the way, or is there an even more specific challenge that I would be better off using?