X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cafc76a4bbbcb59f1c48d9c8f592c671238ffb51..fef5c55604e20e2a90843a2278b1f5c8c817dcee:/src/common/init.cpp diff --git a/src/common/init.cpp b/src/common/init.cpp index 2fd5771f04..a67f723b64 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -35,6 +35,7 @@ #include "wx/ptr_scpd.h" #include "wx/module.h" +#include "wx/except.h" #if defined(__WXMSW__) && defined(__WXDEBUG__) #include "wx/msw/msvcrt.h" @@ -393,20 +394,29 @@ int wxEntryReal(int& argc, wxChar **argv) WX_SUPPRESS_UNUSED_WARN(cleanupOnExit); - // app initialization - if ( !wxTheApp->CallOnInit() ) + wxTRY { - // don't call OnExit() if OnInit() failed - return -1; - } - // app execution - int retValue = wxTheApp->OnRun(); + // app initialization + if ( !wxTheApp->CallOnInit() ) + { + // don't call OnExit() if OnInit() failed + return -1; + } - // app clean up - wxTheApp->OnExit(); + // ensure that OnExit() is called if OnInit() had succeeded + class CallOnExit + { + public: + ~CallOnExit() { wxTheApp->OnExit(); } + } callOnExit; + + WX_SUPPRESS_UNUSED_WARN(callOnExit); - return retValue; + // app execution + return wxTheApp->OnRun(); + } + wxCATCH_ALL( wxTheApp->OnUnhandledException(); return -1; ) } // wrap real wxEntry in a try-except block to be able to call