Prev: Template classes with virtual member functions
Next: own stackframe -> prob with exception handling
From: Christian Hackl on 12 Mar 2010 10:13 Hi everyone, I do not want the Abort/Retry/Ignore dialog to be opened by abort() on assertions in a Win32 GUI application. Let's say I have this piece of code: #include <windows.h> #include <cassert> extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { assert(false); } And I compile and run it like this: cl /nologo main.cpp main.exe What I want now is to have just the usual "An unhandled Win32 exception ecc." error message box with an OK button and immediate program termination afterwards. I've read the documentation on abort() at MSDN [1], but what is explained there is not at all what happens on my machine. First, it says: | When the application is linked with a debug version of the run-time | libraries, abort creates a message box with three buttons: Abort, | Retry, and Ignore. On my computer it appears even with the release versions of the run-time libraries. Then it says: | If the user clicks Ignore, abort continues with its normal execution: | creating the message box with the OK button. If I click Ignore, there's no message box. The application just continues instead of terminating, which is exactly what I want to forbid in case of an assertion... [1] http://msdn.microsoft.com/en-us/library/k089yyh0(VS.80).aspx -- Christian Hackl hacki(a)sbox.tugraz.at Milano 2008/2009 -- L'Italia chiam�, s�!
From: John H. on 12 Mar 2010 13:34 Christian Hackl wrote: > I do not want the Abort/Retry/Ignore dialog to be opened by abort() on > assertions in a Win32 GUI application. I agree that the MSDN docs on this do not seem to be correct. To get behavior closer to what you want try adding _set_error_mode(_OUT_TO_STDERR); You could also try rolling your own version of assert to make the message and actions more along the lines of what you wish to say and do.
From: Christian Hackl on 14 Mar 2010 15:25 John H. ha scritto: > Christian Hackl wrote: >> I do not want the Abort/Retry/Ignore dialog to be opened by abort() on >> assertions in a Win32 GUI application. > > I agree that the MSDN docs on this do not seem to be correct. To get > behavior closer to what you want try adding > _set_error_mode(_OUT_TO_STDERR); Thank you! That did the trick. No more ignoring of critical errors! :) I still wonder, though, if there's some way other than calling a function from within the code. I thought I could control this behaviour with some compiler or linker flag... -- Christian Hackl hacki(a)sbox.tugraz.at Milano 2008/2009 -- L'Italia chiam�, s�!
From: Martin B. on 14 Mar 2010 17:53 On 12.03.2010 16:13, Christian Hackl wrote: > Hi everyone, > > I do not want the Abort/Retry/Ignore dialog to be opened by abort() on > assertions in a Win32 GUI application. Let's say I have this piece of code: > > #include <windows.h> > #include <cassert> > > extern "C" int WINAPI WinMain(HINSTANCE hInstance, > HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) > { > assert(false); > } > > And I compile and run it like this: > > cl /nologo main.cpp > main.exe > > What I want now is to have just the usual "An unhandled Win32 exception > ecc." error message box with an OK button and immediate program > termination afterwards. > > ... You could also debug into assert() / abort() to get an idea what customizations points are passed along the way. IIRC one can tweak the behaviour of std::abort() via registering some SIGNAL handlers. br, Martin
|
Pages: 1 Prev: Template classes with virtual member functions Next: own stackframe -> prob with exception handling |