From 5cd3213b65b195186b5ec65a3ae73bb0dc7ec19a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 9 Dec 2009 14:58:56 +0000 Subject: [PATCH] Override OnAssertFailure() and not deprecated OnAssert() in except sample. Also make the overridden version more interesting instead of just calling the base class method from it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62840 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/except/except.cpp | 41 ++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/samples/except/except.cpp b/samples/except/except.cpp index ed04aec596..db66fb76de 100644 --- a/samples/except/except.cpp +++ b/samples/except/except.cpp @@ -91,14 +91,13 @@ public: // crash (e.g. dereferencing null pointer, division by 0, ...) virtual void OnFatalException(); -#ifdef __WXDEBUG__ - // in debug mode, you can override this function to do something different - // (e.g. log the assert to file) whenever an assertion fails - virtual void OnAssert(const wxChar *file, - int line, - const wxChar *cond, - const wxChar *msg); -#endif // __WXDEBUG__ + // you can override this function to do something different (e.g. log the + // assert to file) whenever an assertion fails + virtual void OnAssertFailure(const wxChar *file, + int line, + const wxChar *func, + const wxChar *cond, + const wxChar *msg); }; // Define a new frame type: this is going to be our main frame @@ -302,19 +301,25 @@ void MyApp::OnFatalException() wxT("wxExcept Sample"), wxOK | wxICON_ERROR); } -#ifdef __WXDEBUG__ - -void MyApp::OnAssert(const wxChar *file, - int line, - const wxChar *cond, - const wxChar *msg) +void MyApp::OnAssertFailure(const wxChar *file, + int line, + const wxChar *func, + const wxChar *cond, + const wxChar *msg) { - // we don't have anything special to do here - wxApp::OnAssert(file, line, cond, msg); + if ( wxMessageBox + ( + wxString::Format("An assert failed in %s().", func) + + "\n" + "Do you want to call the default assert handler?", + "wxExcept Sample", + wxYES_NO | wxICON_QUESTION + ) == wxYES ) + { + wxApp::OnAssertFailure(file, line, func, cond, msg); + } } -#endif // __WXDEBUG__ - // ============================================================================ // MyFrame implementation // ============================================================================ -- 2.47.2