![]() |
MechSys
1.0
Computing library for simulations in continuum and discrete mechanics
|
00001 /************************************************************************ 00002 * MechSys - Open Library for Mechanical Systems * 00003 * Copyright (C) 2005 Dorival M. Pedroso, Raul Durand * 00004 * Copyright (C) 2009 Sergio Galindo * 00005 * * 00006 * This program is free software: you can redistribute it and/or modify * 00007 * it under the terms of the GNU General Public License as published by * 00008 * the Free Software Foundation, either version 3 of the License, or * 00009 * any later version. * 00010 * * 00011 * This program is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00018 ************************************************************************/ 00019 00020 #ifndef MECHSYS_GUI_WXMYAPP_H 00021 #define MECHSYS_GUI_WXMYAPP_H 00022 00023 // wxWidgets 00024 #include "wx/app.h" 00025 #include "wx/utils.h" 00026 #include "wx/msgdlg.h" 00027 #include "wx/log.h" 00028 00029 // MechSys 00030 #include <mechsys/util/fatal.h> 00031 00032 class MyApp : public wxApp 00033 { 00034 public: 00035 // Destructor 00036 virtual ~MyApp () {} 00037 00038 // program startup 00039 virtual bool OnInit(); 00040 00041 // 2nd-level exception handling: we get all the exceptions occurring in any 00042 // event handler here 00043 virtual bool OnExceptionInMainLoop(); 00044 00045 // 3rd, and final, level exception handling: whenever an unhandled 00046 // exception is caught, this function is called 00047 virtual void OnUnhandledException(); 00048 00049 // and now for something different: this function is called in case of a 00050 // crash (e.g. dereferencing null pointer, division by 0, ...) 00051 virtual void OnFatalException(); 00052 }; 00053 00054 00056 00057 00058 bool MyApp::OnInit() 00059 { 00060 MyFrame * frame = new MyFrame(MYAPP_TITLE); 00061 frame->Show (true); 00062 SetTopWindow (frame); 00063 return true; 00064 } 00065 00066 bool MyApp::OnExceptionInMainLoop() 00067 { 00068 String msg; 00069 try 00070 { 00071 msg = "MyApp::OnExceptionInMainLoop:: Internal Error"; 00072 throw; 00073 } 00074 catch (Fatal * e) { msg.Printf("Fatal: %s",e->Msg().CStr()); delete e; } 00075 catch (char const * m) { msg.Printf("Fatal: %s",m); } 00076 catch (std::exception & e) { msg.Printf("Fatal: %s",e.what()); } 00077 00078 wxMessageBox(msg.CStr(), _("Exception caught."), wxOK | wxICON_ERROR); 00079 00080 return true; 00081 } 00082 00083 void MyApp::OnUnhandledException() 00084 { 00085 // this shows how we may let some exception propagate uncaught 00086 try 00087 { 00088 throw; 00089 } 00090 catch ( ... ) 00091 { 00092 wxMessageBox(_("Unhandled exception caught, program will terminate."), 00093 _("Exception caught."), wxOK | wxICON_ERROR); 00094 } 00095 } 00096 00097 void MyApp::OnFatalException() 00098 { 00099 wxMessageBox(_("Program has crashed and will terminate."), 00100 _("Exception caught."), wxOK | wxICON_ERROR); 00101 } 00102 00103 DECLARE_APP (MyApp) 00104 IMPLEMENT_APP (MyApp) 00105 00106 #endif // MECHSYS_GUI_WXMYAPP_H