X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d32b901bac42e4f8833720fd6eee60de7d870e0d..f4bb632cde9cc60fa89f173f0d33c5881794cc68:/samples/except/except.cpp?ds=sidebyside diff --git a/samples/except/except.cpp b/samples/except/except.cpp index aa217e4afa..f5423780ab 100644 --- a/samples/except/except.cpp +++ b/samples/except/except.cpp @@ -1,11 +1,11 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: except.cpp -// Purpose: Except wxWidgets sample -// Author: Julian Smart +// Name: samples/except/except.cpp +// Purpose: shows how C++ exceptions can be used in wxWidgets +// Author: Vadim Zeitlin // Modified by: -// Created: 04/01/98 +// Created: 2003-09-17 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart +// Copyright: (c) 2003-2005 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -24,6 +24,10 @@ #pragma hdrstop #endif +#if !wxUSE_EXCEPTIONS + #error "This sample only works with wxUSE_EXCEPTIONS == 1" +#endif // !wxUSE_EXCEPTIONS + // for all others, include the necessary headers (this file is usually all you // need because it includes almost all "standard" wxWidgets headers) #ifndef WX_PRECOMP @@ -39,6 +43,7 @@ #include "wx/utils.h" #include "wx/msgdlg.h" + #include "wx/icon.h" #endif // ---------------------------------------------------------------------------- @@ -107,6 +112,7 @@ public: // event handlers void OnThrowInt(wxCommandEvent& event); void OnThrowObject(wxCommandEvent& event); + void OnCrash(wxCommandEvent& event); private: DECLARE_EVENT_TABLE() @@ -134,6 +140,7 @@ enum // control ids Except_ThrowInt = 100, Except_ThrowObject, + Except_Crash, // menu items Except_ThrowString = 200, @@ -160,6 +167,7 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyDialog, wxDialog) EVT_BUTTON(Except_ThrowInt, MyDialog::OnThrowInt) EVT_BUTTON(Except_ThrowObject, MyDialog::OnThrowObject) + EVT_BUTTON(Except_Crash, MyDialog::OnCrash) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWidgets to create @@ -311,6 +319,8 @@ MyDialog::MyDialog(wxFrame *parent) 0, wxCENTRE | wxALL, 5); sizerTop->Add(new wxButton(this, Except_ThrowObject, _T("Throw &object")), 0, wxCENTRE | wxALL, 5); + sizerTop->Add(new wxButton(this, Except_Crash, _T("&Crash")), + 0, wxCENTRE | wxALL, 5); sizerTop->Add(new wxButton(this, wxID_CANCEL, _T("&Cancel")), 0, wxCENTRE | wxALL, 5); @@ -328,3 +338,9 @@ void MyDialog::OnThrowObject(wxCommandEvent& WXUNUSED(event)) throw MyException(_T("Exception thrown from the dialog")); } +void MyDialog::OnCrash(wxCommandEvent& WXUNUSED(event)) +{ + char *p = 0; + strcpy(p, "Let's crash"); +} +