added a test for/example of assert dialog box

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32911 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2005-03-19 16:14:58 +00:00
parent 6c8f8d923a
commit 3eeb7e105e

View File

@@ -90,6 +90,15 @@ public:
// and now for something different: this function is called in case of a // and now for something different: this function is called in case of a
// crash (e.g. dereferencing null pointer, division by 0, ...) // crash (e.g. dereferencing null pointer, division by 0, ...)
virtual void OnFatalException(); 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__
}; };
// Define a new frame type: this is going to be our main frame // Define a new frame type: this is going to be our main frame
@@ -118,6 +127,11 @@ public:
// catch exceptions which occur in MyFrame methods here // catch exceptions which occur in MyFrame methods here
virtual bool ProcessEvent(wxEvent& event); virtual bool ProcessEvent(wxEvent& event);
#ifdef __WXDEBUG__
// show how an assert failure message box looks like
void OnShowAssert(wxCommandEvent& event);
#endif // __WXDEBUG__
private: private:
// any class wishing to process wxWidgets events must use this macro // any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@@ -170,7 +184,10 @@ enum
Except_Crash, Except_Crash,
#if wxUSE_ON_FATAL_EXCEPTION #if wxUSE_ON_FATAL_EXCEPTION
Except_HandleCrash, Except_HandleCrash,
#endif #endif // wxUSE_ON_FATAL_EXCEPTION
#ifdef __WXDEBUG__
Except_ShowAssert,
#endif // __WXDEBUG__
Except_Dialog, Except_Dialog,
Except_Quit = wxID_EXIT, Except_Quit = wxID_EXIT,
@@ -195,7 +212,10 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Except_Crash, MyFrame::OnCrash) EVT_MENU(Except_Crash, MyFrame::OnCrash)
#if wxUSE_ON_FATAL_EXCEPTION #if wxUSE_ON_FATAL_EXCEPTION
EVT_MENU(Except_HandleCrash, MyFrame::OnHandleCrash) EVT_MENU(Except_HandleCrash, MyFrame::OnHandleCrash)
#endif #endif // wxUSE_ON_FATAL_EXCEPTION
#ifdef __WXDEBUG__
EVT_MENU(Except_ShowAssert, MyFrame::OnShowAssert)
#endif // __WXDEBUG__
END_EVENT_TABLE() END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyDialog, wxDialog) BEGIN_EVENT_TABLE(MyDialog, wxDialog)
@@ -277,6 +297,19 @@ void MyApp::OnFatalException()
_T("wxExcept Sample"), wxOK | wxICON_ERROR); _T("wxExcept Sample"), wxOK | wxICON_ERROR);
} }
#ifdef __WXDEBUG__
void MyApp::OnAssert(const wxChar *file,
int line,
const wxChar *cond,
const wxChar *msg)
{
// we don't have anything special to do here
wxApp::OnAssert(file, line, cond, msg);
}
#endif // __WXDEBUG__
// ============================================================================ // ============================================================================
// MyFrame implementation // MyFrame implementation
// ============================================================================ // ============================================================================
@@ -304,7 +337,11 @@ MyFrame::MyFrame()
#if wxUSE_ON_FATAL_EXCEPTION #if wxUSE_ON_FATAL_EXCEPTION
menuFile->AppendCheckItem(Except_HandleCrash, _T("&Handle crashes\tCtrl-H")); menuFile->AppendCheckItem(Except_HandleCrash, _T("&Handle crashes\tCtrl-H"));
menuFile->AppendSeparator(); menuFile->AppendSeparator();
#endif #endif // wxUSE_ON_FATAL_EXCEPTION
#ifdef __WXDEBUG__
menuFile->Append(Except_ShowAssert, _T("Provoke &assert failure\tCtrl-A"));
menuFile->AppendSeparator();
#endif // __WXDEBUG__
menuFile->Append(Except_Quit, _T("E&xit\tCtrl-Q"), _T("Quit this program")); menuFile->Append(Except_Quit, _T("E&xit\tCtrl-Q"), _T("Quit this program"));
wxMenu *helpMenu = new wxMenu; wxMenu *helpMenu = new wxMenu;
@@ -395,7 +432,18 @@ void MyFrame::OnHandleCrash(wxCommandEvent& event)
wxHandleFatalExceptions(event.IsChecked()); wxHandleFatalExceptions(event.IsChecked());
} }
#endif #endif // wxUSE_ON_FATAL_EXCEPTION
#ifdef __WXDEBUG__
void MyFrame::OnShowAssert(wxCommandEvent& WXUNUSED(event))
{
// provoke an assert from wxArrayString
wxArrayString arr;
arr[0];
}
#endif // __WXDEBUG__
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{ {