2003-09-17 19:37:54 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2005-01-03 10:47:57 -05:00
|
|
|
// Name: samples/except/except.cpp
|
|
|
|
// Purpose: shows how C++ exceptions can be used in wxWidgets
|
|
|
|
// Author: Vadim Zeitlin
|
2003-09-17 19:37:54 -04:00
|
|
|
// Modified by:
|
2005-01-03 10:47:57 -05:00
|
|
|
// Created: 2003-09-17
|
2003-09-17 19:37:54 -04:00
|
|
|
// RCS-ID: $Id$
|
2005-01-03 10:47:57 -05:00
|
|
|
// Copyright: (c) 2003-2005 Vadim Zeitlin
|
2003-09-17 19:37:54 -04:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2005-01-03 10:47:57 -05:00
|
|
|
#if !wxUSE_EXCEPTIONS
|
|
|
|
#error "This sample only works with wxUSE_EXCEPTIONS == 1"
|
|
|
|
#endif // !wxUSE_EXCEPTIONS
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
2004-05-25 07:20:37 -04:00
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
2003-09-17 19:37:54 -04:00
|
|
|
#ifndef WX_PRECOMP
|
2003-09-18 11:52:34 -04:00
|
|
|
#include "wx/log.h"
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
#include "wx/dialog.h"
|
2003-09-18 11:52:34 -04:00
|
|
|
#include "wx/menu.h"
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
#include "wx/button.h"
|
|
|
|
#include "wx/sizer.h"
|
|
|
|
|
2004-05-28 06:45:07 -04:00
|
|
|
#include "wx/utils.h"
|
|
|
|
#include "wx/msgdlg.h"
|
2005-02-06 05:41:35 -05:00
|
|
|
#include "wx/icon.h"
|
2003-09-17 19:37:54 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// the application icon (under Windows and OS/2 it is in resources)
|
|
|
|
#if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXMGL__) || defined(__WXX11__)
|
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
|
|
|
|
2005-02-11 17:33:09 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static void DoCrash()
|
|
|
|
{
|
|
|
|
char *p = 0;
|
|
|
|
strcpy(p, "Let's crash");
|
|
|
|
}
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// override base class virtuals
|
|
|
|
// ----------------------------
|
|
|
|
|
|
|
|
// program startup
|
|
|
|
virtual bool OnInit();
|
|
|
|
|
2005-05-31 05:20:43 -04:00
|
|
|
// 2nd-level exception handling: we get all the exceptions occurring in any
|
2003-09-17 19:37:54 -04:00
|
|
|
// event handler here
|
2005-02-11 17:33:09 -05:00
|
|
|
virtual bool OnExceptionInMainLoop();
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
// 3rd, and final, level exception handling: whenever an unhandled
|
|
|
|
// exception is caught, this function is called
|
|
|
|
virtual void OnUnhandledException();
|
2005-02-11 17:33:09 -05:00
|
|
|
|
|
|
|
// and now for something different: this function is called in case of a
|
|
|
|
// crash (e.g. dereferencing null pointer, division by 0, ...)
|
|
|
|
virtual void OnFatalException();
|
2005-03-19 11:14:58 -05:00
|
|
|
|
|
|
|
#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__
|
2003-09-17 19:37:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Define a new frame type: this is going to be our main frame
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor(s)
|
2005-02-11 17:33:09 -05:00
|
|
|
MyFrame();
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
// event handlers (these functions should _not_ be virtual)
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
|
|
|
void OnDialog(wxCommandEvent& event);
|
2005-02-11 17:33:09 -05:00
|
|
|
|
|
|
|
void OnThrowInt(wxCommandEvent& event);
|
2003-09-17 19:37:54 -04:00
|
|
|
void OnThrowString(wxCommandEvent& event);
|
2005-02-11 17:33:09 -05:00
|
|
|
void OnThrowObject(wxCommandEvent& event);
|
|
|
|
void OnThrowUnhandled(wxCommandEvent& event);
|
|
|
|
|
|
|
|
void OnCrash(wxCommandEvent& event);
|
2005-03-03 14:46:15 -05:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
2005-02-11 17:33:09 -05:00
|
|
|
void OnHandleCrash(wxCommandEvent& event);
|
2005-03-03 14:46:15 -05:00
|
|
|
#endif
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
// 1st-level exception handling: we overload ProcessEvent() to be able to
|
|
|
|
// catch exceptions which occur in MyFrame methods here
|
|
|
|
virtual bool ProcessEvent(wxEvent& event);
|
|
|
|
|
2005-03-19 11:14:58 -05:00
|
|
|
#ifdef __WXDEBUG__
|
|
|
|
// show how an assert failure message box looks like
|
|
|
|
void OnShowAssert(wxCommandEvent& event);
|
|
|
|
#endif // __WXDEBUG__
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
private:
|
2004-05-25 07:20:37 -04:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2003-09-17 19:37:54 -04:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// A simple dialog which has only some buttons to throw exceptions
|
|
|
|
class MyDialog : public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyDialog(wxFrame *parent);
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
void OnThrowInt(wxCommandEvent& event);
|
|
|
|
void OnThrowObject(wxCommandEvent& event);
|
2005-01-03 10:47:57 -05:00
|
|
|
void OnCrash(wxCommandEvent& event);
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// A trivial exception class
|
|
|
|
class MyException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyException(const wxString& msg) : m_msg(msg) { }
|
|
|
|
|
|
|
|
const wxChar *what() const { return m_msg.c_str(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxString m_msg;
|
|
|
|
};
|
|
|
|
|
2005-02-11 17:33:09 -05:00
|
|
|
// Another exception class which just has to be different from anything else
|
|
|
|
class UnhandledException
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
// control ids and menu items
|
2005-03-03 14:46:15 -05:00
|
|
|
Except_ThrowInt = wxID_HIGHEST,
|
2005-02-11 17:33:09 -05:00
|
|
|
Except_ThrowString,
|
2003-09-17 19:37:54 -04:00
|
|
|
Except_ThrowObject,
|
2005-02-11 17:33:09 -05:00
|
|
|
Except_ThrowUnhandled,
|
2005-01-03 10:47:57 -05:00
|
|
|
Except_Crash,
|
2005-03-03 14:46:15 -05:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
2005-02-11 17:33:09 -05:00
|
|
|
Except_HandleCrash,
|
2005-03-19 11:14:58 -05:00
|
|
|
#endif // wxUSE_ON_FATAL_EXCEPTION
|
|
|
|
#ifdef __WXDEBUG__
|
|
|
|
Except_ShowAssert,
|
|
|
|
#endif // __WXDEBUG__
|
2003-09-17 19:37:54 -04:00
|
|
|
Except_Dialog,
|
|
|
|
|
|
|
|
Except_Quit = wxID_EXIT,
|
|
|
|
Except_About = wxID_ABOUT
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// event tables and other macros for wxWidgets
|
2003-09-17 19:37:54 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// the event tables connect the wxWidgets events with the functions (event
|
2003-09-17 19:37:54 -04:00
|
|
|
// handlers) which process them. It can be also done at run-time, but for the
|
|
|
|
// simple menu events like this the static method is much simpler.
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU(Except_Quit, MyFrame::OnQuit)
|
|
|
|
EVT_MENU(Except_About, MyFrame::OnAbout)
|
|
|
|
EVT_MENU(Except_Dialog, MyFrame::OnDialog)
|
2005-02-11 17:33:09 -05:00
|
|
|
EVT_MENU(Except_ThrowInt, MyFrame::OnThrowInt)
|
2003-09-17 19:37:54 -04:00
|
|
|
EVT_MENU(Except_ThrowString, MyFrame::OnThrowString)
|
2005-02-11 17:33:09 -05:00
|
|
|
EVT_MENU(Except_ThrowObject, MyFrame::OnThrowObject)
|
|
|
|
EVT_MENU(Except_ThrowUnhandled, MyFrame::OnThrowUnhandled)
|
|
|
|
EVT_MENU(Except_Crash, MyFrame::OnCrash)
|
2005-03-03 14:46:15 -05:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
2005-02-11 17:33:09 -05:00
|
|
|
EVT_MENU(Except_HandleCrash, MyFrame::OnHandleCrash)
|
2005-03-19 11:14:58 -05:00
|
|
|
#endif // wxUSE_ON_FATAL_EXCEPTION
|
|
|
|
#ifdef __WXDEBUG__
|
|
|
|
EVT_MENU(Except_ShowAssert, MyFrame::OnShowAssert)
|
|
|
|
#endif // __WXDEBUG__
|
2003-09-17 19:37:54 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyDialog, wxDialog)
|
|
|
|
EVT_BUTTON(Except_ThrowInt, MyDialog::OnThrowInt)
|
|
|
|
EVT_BUTTON(Except_ThrowObject, MyDialog::OnThrowObject)
|
2005-01-03 10:47:57 -05:00
|
|
|
EVT_BUTTON(Except_Crash, MyDialog::OnCrash)
|
2003-09-17 19:37:54 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// Create a new application object: this macro will allow wxWidgets to create
|
2003-09-17 19:37:54 -04:00
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also implements the accessor function
|
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
|
|
|
// not wxApp)
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// MyApp implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
// create the main application window
|
2005-02-11 17:33:09 -05:00
|
|
|
MyFrame *frame = new MyFrame();
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
// and show it (the frames, unlike simple controls, are not shown when
|
|
|
|
// created initially)
|
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
// success: wxApp::OnRun() will be called which will enter the main message
|
|
|
|
// loop and the application will run. If we returned false here, the
|
|
|
|
// application would exit immediately.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-02-11 17:33:09 -05:00
|
|
|
bool MyApp::OnExceptionInMainLoop()
|
2003-09-17 19:37:54 -04:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
throw;
|
2003-09-17 19:37:54 -04:00
|
|
|
}
|
|
|
|
catch ( int i )
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
wxLogWarning(_T("Caught an int %d in MyApp."), i);
|
2003-09-17 19:37:54 -04:00
|
|
|
}
|
2005-02-11 17:33:09 -05:00
|
|
|
catch ( MyException& e )
|
|
|
|
{
|
|
|
|
wxLogWarning(_T("Caught MyException(%s) in MyApp."), e.what());
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2003-09-17 19:37:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyApp::OnUnhandledException()
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
// this shows how we may let some exception propagate uncaught
|
|
|
|
try
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch ( UnhandledException& )
|
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("Unhandled exception caught, program will terminate."),
|
|
|
|
_T("wxExcept Sample"), wxOK | wxICON_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyApp::OnFatalException()
|
|
|
|
{
|
|
|
|
wxMessageBox(_T("Program has crashed and will terminate."),
|
2003-09-17 19:37:54 -04:00
|
|
|
_T("wxExcept Sample"), wxOK | wxICON_ERROR);
|
|
|
|
}
|
|
|
|
|
2005-03-19 11:14:58 -05:00
|
|
|
#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__
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
// ============================================================================
|
|
|
|
// MyFrame implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// frame constructor
|
2005-02-11 17:33:09 -05:00
|
|
|
MyFrame::MyFrame()
|
|
|
|
: wxFrame(NULL, wxID_ANY, _T("Except wxWidgets App"),
|
|
|
|
wxPoint(50, 50), wxSize(450, 340))
|
2003-09-17 19:37:54 -04:00
|
|
|
{
|
|
|
|
// set the frame icon
|
2004-07-24 06:46:54 -04:00
|
|
|
SetIcon(wxICON(sample));
|
2003-09-17 19:37:54 -04:00
|
|
|
|
|
|
|
#if wxUSE_MENUS
|
|
|
|
// create a menu bar
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
|
|
|
menuFile->Append(Except_Dialog, _T("Show &dialog\tCtrl-D"));
|
2005-02-11 17:33:09 -05:00
|
|
|
menuFile->AppendSeparator();
|
|
|
|
menuFile->Append(Except_ThrowInt, _T("Throw an &int\tCtrl-I"));
|
2003-09-17 19:37:54 -04:00
|
|
|
menuFile->Append(Except_ThrowString, _T("Throw a &string\tCtrl-S"));
|
2005-02-11 17:33:09 -05:00
|
|
|
menuFile->Append(Except_ThrowObject, _T("Throw an &object\tCtrl-O"));
|
|
|
|
menuFile->Append(Except_ThrowUnhandled,
|
|
|
|
_T("Throw &unhandled exception\tCtrl-U"));
|
|
|
|
menuFile->Append(Except_Crash, _T("&Crash\tCtrl-C"));
|
|
|
|
menuFile->AppendSeparator();
|
2005-03-03 14:46:15 -05:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
2005-02-11 17:33:09 -05:00
|
|
|
menuFile->AppendCheckItem(Except_HandleCrash, _T("&Handle crashes\tCtrl-H"));
|
2003-09-17 19:37:54 -04:00
|
|
|
menuFile->AppendSeparator();
|
2005-03-19 11:14:58 -05:00
|
|
|
#endif // wxUSE_ON_FATAL_EXCEPTION
|
|
|
|
#ifdef __WXDEBUG__
|
|
|
|
menuFile->Append(Except_ShowAssert, _T("Provoke &assert failure\tCtrl-A"));
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
#endif // __WXDEBUG__
|
2003-09-17 19:37:54 -04:00
|
|
|
menuFile->Append(Except_Quit, _T("E&xit\tCtrl-Q"), _T("Quit this program"));
|
|
|
|
|
|
|
|
wxMenu *helpMenu = new wxMenu;
|
|
|
|
helpMenu->Append(Except_About, _T("&About...\tF1"), _T("Show about dialog"));
|
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
|
|
|
menuBar->Append(menuFile, _T("&File"));
|
|
|
|
menuBar->Append(helpMenu, _T("&Help"));
|
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
#endif // wxUSE_MENUS
|
|
|
|
|
|
|
|
#if wxUSE_STATUSBAR && !defined(__WXWINCE__)
|
|
|
|
// create a status bar just for fun (by default with 1 pane only)
|
|
|
|
CreateStatusBar(2);
|
2004-05-25 07:20:37 -04:00
|
|
|
SetStatusText(_T("Welcome to wxWidgets!"));
|
2003-09-17 19:37:54 -04:00
|
|
|
#endif // wxUSE_STATUSBAR
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MyFrame::ProcessEvent(wxEvent& event)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return wxFrame::ProcessEvent(event);
|
|
|
|
}
|
|
|
|
catch ( const wxChar *msg )
|
|
|
|
{
|
|
|
|
wxLogMessage(_T("Caught a string \"%s\" in MyFrame"), msg);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// true is to force the frame to close
|
|
|
|
Close(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDialog(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2003-09-20 12:23:51 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
MyDialog dlg(this);
|
2003-09-17 19:37:54 -04:00
|
|
|
|
2003-09-20 12:23:51 -04:00
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
catch ( ... )
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
wxLogWarning(_T("An exception in MyDialog"));
|
|
|
|
|
2003-09-20 12:23:51 -04:00
|
|
|
Destroy();
|
|
|
|
throw;
|
|
|
|
}
|
2003-09-17 19:37:54 -04:00
|
|
|
}
|
|
|
|
|
2005-02-11 17:33:09 -05:00
|
|
|
void MyFrame::OnThrowInt(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
throw -17;
|
|
|
|
}
|
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
void MyFrame::OnThrowString(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
throw _T("string thrown from MyFrame");
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnThrowObject(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
throw MyException(_T("Exception thrown from MyFrame"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnThrowUnhandled(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
throw UnhandledException();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnCrash(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
DoCrash();
|
|
|
|
}
|
|
|
|
|
2005-03-03 14:46:15 -05:00
|
|
|
#if wxUSE_ON_FATAL_EXCEPTION
|
|
|
|
|
2005-02-11 17:33:09 -05:00
|
|
|
void MyFrame::OnHandleCrash(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
wxHandleFatalExceptions(event.IsChecked());
|
2003-09-17 19:37:54 -04:00
|
|
|
}
|
|
|
|
|
2005-03-19 11:14:58 -05:00
|
|
|
#endif // wxUSE_ON_FATAL_EXCEPTION
|
|
|
|
|
|
|
|
#ifdef __WXDEBUG__
|
|
|
|
|
|
|
|
void MyFrame::OnShowAssert(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
// provoke an assert from wxArrayString
|
|
|
|
wxArrayString arr;
|
|
|
|
arr[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WXDEBUG__
|
2005-03-03 14:46:15 -05:00
|
|
|
|
2003-09-17 19:37:54 -04:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _T("This is the About dialog of the except sample.\n")
|
|
|
|
_T("Welcome to %s"), wxVERSION_STRING);
|
|
|
|
|
|
|
|
wxMessageBox(msg, _T("About Except"), wxOK | wxICON_INFORMATION, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// MyDialog implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
MyDialog::MyDialog(wxFrame *parent)
|
2004-05-28 06:45:07 -04:00
|
|
|
: wxDialog(parent, wxID_ANY, wxString(_T("Throw exception dialog")))
|
2003-09-17 19:37:54 -04:00
|
|
|
{
|
|
|
|
wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
|
|
|
|
|
|
|
|
sizerTop->Add(new wxButton(this, Except_ThrowInt, _T("Throw &int")),
|
|
|
|
0, wxCENTRE | wxALL, 5);
|
|
|
|
sizerTop->Add(new wxButton(this, Except_ThrowObject, _T("Throw &object")),
|
|
|
|
0, wxCENTRE | wxALL, 5);
|
2005-01-03 10:47:57 -05:00
|
|
|
sizerTop->Add(new wxButton(this, Except_Crash, _T("&Crash")),
|
|
|
|
0, wxCENTRE | wxALL, 5);
|
2003-09-17 19:37:54 -04:00
|
|
|
sizerTop->Add(new wxButton(this, wxID_CANCEL, _T("&Cancel")),
|
|
|
|
0, wxCENTRE | wxALL, 5);
|
|
|
|
|
|
|
|
SetSizer(sizerTop);
|
|
|
|
sizerTop->Fit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyDialog::OnThrowInt(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
throw 17;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyDialog::OnThrowObject(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
throw MyException(_T("Exception thrown from MyDialog"));
|
2003-09-17 19:37:54 -04:00
|
|
|
}
|
|
|
|
|
2005-01-03 10:47:57 -05:00
|
|
|
void MyDialog::OnCrash(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2005-02-11 17:33:09 -05:00
|
|
|
DoCrash();
|
2005-01-03 10:47:57 -05:00
|
|
|
}
|
|
|
|
|