Normally an assertion failure triggered through the assert() macro would cause an error message that contains source file and line number (__FILE__, __LINE__). But when running your program in a GUI you only get a MessageBox which unfortunately does not appear to show these details. I don't know a method to get this information displayed in that case.
Therefore attaching with a debugger seems to be the only way, as Jon stated.
To avoid this kind of annoying problem, but also to be able to set a breakpoint to the line where abort() is called (often I do not have the MSVC++ library source code at hand so I can't set a breakpoint into the code that implements the assert() macro!), I always use my own ASSERT() macro, and I define DEBUG in the debug version instead of defining NDEBUG in the release version. Example:
Code: Select all
// header file
#ifdef DEBUG
void raiseAssertionFailure(char const * file, int line, char const * expr);
#define ASSERT(expr) if (!(expr)) raiseAssertionFailure(__FILE__, __LINE__, #expr)
#else
#define ASSERT(expr)
#endif /* DEBUG */
// cpp file
#ifdef DEBUG
#include <cstdio>
#include <cstdlib>
#endif /* DEBUG */
#ifdef DEBUG
void raiseAssertionFailure(char const * file, int line, char const * expr)
{
fprintf(stderr, "*** ASSERTION FAILED: \"%s\" (%s, line %d)\n", expr, file, line);
abort();
}
#endif /* DEBUG */
Of course using cerr << ... instead of fprintf() is fine here as well. Just don't make raiseAssertionFailure() a macro itself (which would be the same as doing fprintf + abort directly within ASSERT), it will bloat your code.
You can also use the _ASSERT or _ASSERTE macros but AFAIK these are Microsoft extensions so you lose portability.