If an assert occurred while handling an exception generated by a previous
assert handler, the information about the original assert was lost even if
though it was more important than the secondary assert. Do preserve and show
the original assert message in this case now.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71318
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
+// Information about the last not yet handled assertion.
+static wxString s_lastAssertMessage;
+
static wxString FormatAssertMessage(const wxString& file,
int line,
const wxString& func,
static wxString FormatAssertMessage(const wxString& file,
int line,
const wxString& func,
// fail or whether we need to abort (in this case "msg" will contain the
// explanation why did we decide to do it).
wxString abortReason;
// fail or whether we need to abort (in this case "msg" will contain the
// explanation why did we decide to do it).
wxString abortReason;
+
+ const wxString
+ assertMessage = FormatAssertMessage(file, line, func, cond, msg);
+
if ( !wxIsMainThread() )
{
// Exceptions thrown from worker threads are not caught currently and
// so we'd just die without any useful information -- abort instead.
if ( !wxIsMainThread() )
{
// Exceptions thrown from worker threads are not caught currently and
// so we'd just die without any useful information -- abort instead.
- abortReason = "in a worker thread";
+ abortReason << assertMessage << "in a worker thread.";
}
else if ( uncaught_exception() )
{
// Throwing while already handling an exception would result in
// terminate() being called and we wouldn't get any useful information
// about why the test failed then.
}
else if ( uncaught_exception() )
{
// Throwing while already handling an exception would result in
// terminate() being called and we wouldn't get any useful information
// about why the test failed then.
- abortReason = "while handling an exception";
+ if ( s_lastAssertMessage.empty() )
+ {
+ abortReason << assertMessage << "while handling an exception";
+ }
+ else // In this case the exception is due to a previous assert.
+ {
+ abortReason << s_lastAssertMessage << "\n and another "
+ << assertMessage << " while handling it.";
+ }
}
else // Can "safely" throw from here.
{
}
else // Can "safely" throw from here.
{
+ // Remember this in case another assert happens while handling this
+ // exception: we want to show the original assert as it's usually more
+ // useful to determine the real root of the problem.
+ s_lastAssertMessage = assertMessage;
+
throw TestAssertFailure(file, line, func, cond, msg);
}
throw TestAssertFailure(file, line, func, cond, msg);
}
- wxFprintf(stderr, "%s %s -- aborting.",
- FormatAssertMessage(file, line, func, cond, msg),
- abortReason);
+ wxFputs(abortReason, stderr);
fflush(stderr);
_exit(-1);
}
fflush(stderr);
_exit(-1);
}
#if wxDEBUG_LEVEL
catch ( TestAssertFailure& e )
{
#if wxDEBUG_LEVEL
catch ( TestAssertFailure& e )
{
- msg << FormatAssertMessage(e.m_file, e.m_line, e.m_func,
- e.m_cond, e.m_msg);
+ msg = s_lastAssertMessage;
+ s_lastAssertMessage.clear();
}
#endif // wxDEBUG_LEVEL
#ifdef wxUSE_VC_CRTDBG
}
#endif // wxDEBUG_LEVEL
#ifdef wxUSE_VC_CRTDBG