Discussion:
Avoiding the Abort/Retry/Ignore dialog on assertion
(too old to reply)
Christian Hackl
2010-03-12 15:13:39 UTC
Permalink
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
***@sbox.tugraz.at

Milano 2008/2009 -- L'Italia chiamò, sì!
John H.
2010-03-12 18:34:29 UTC
Permalink
Post by Christian Hackl
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.
Christian Hackl
2010-03-14 19:25:35 UTC
Permalink
This post might be inappropriate. Click to display it.
Martin B.
2010-03-14 21:53:25 UTC
Permalink
Post by Christian Hackl
Hi everyone,
I do not want the Abort/Retry/Ignore dialog to be opened by abort() on
#include <windows.h>
#include <cassert>
extern "C" int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
assert(false);
}
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

Loading...