views:

467

answers:

4

On Windows/c++, I want to customize the assert dialog box to ignore an assertion forever, so I can be more aggressive with assertions. I understand how hard it is to write a correct assert macro, and do not wish to do this, just hook the dialog code. Is there an easy way (or concise hack) to do this?

article on assert macro dangers (googlecache)

update: more aggressive => use far more frequently and for noncrash bugs. I want to be able to ignore an assertion forever so if a minor bug assertion occurs in a loop it doesn't effectively halt my process.

+2  A: 

If by "more aggressive" you mean using assertions for error handling, then you're better off using exceptions.

Assaf Lavie
i do not
Dustin Getz
+1  A: 

Look into the _CrtSetReportHook function or the newer _CrtSetReportHook2. You can use it to install a hook that remembers "seen" messages, and reports them as handled when seen again.

Andrew Stein
A: 

Follow the teachings of our embedded master Miro Samek:

An exception or a bug?

Scroll down for customizing the behaviour of assert. (But do read everything else.)

Daniel Daranas
the link died :(
Dustin Getz
@Dustin Getz: Thanks for pointing out. I updated it.
Daniel Daranas
A: 

If the code doesn't need to be thread-safe, and if you only want to ignore the assertions "forever" in the sense that they will be ignored after the first time each time the program is run, and not forever in the sense that you ignore it the first time and after that it never fires again for all program runs, then just combine the assertion test with a static bool that's set to false by default.

void someFunc(...)
{
...
static bool bFireAssertion( false );

ASSERT( bFireAssertion || <your assertion test> );
...
}

then when you want it to stop firing, set bFireAssertion to true from within the debugger. Since it will always be true, the ASSERT will short-circuit and never evaluate your test anymore.

Michel
nice idea, but needs to be a checkbox in the gui.
Dustin Getz