diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index 7cc2694a3..f6d6ebc1d 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -340,6 +340,31 @@ void AegisubApp::OnFatalException() { #endif +void AegisubApp::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& event) const { +#define SHOW_EXCEPTION(str) wxMessageBox(str, L"Exception in event handler", wxOK|wxICON_ERROR|wxSTAY_ON_TOP) + try { + wxApp::HandleEvent(handler, func, event); + } + catch (const agi::Exception &e) { + SHOW_EXCEPTION(lagi_wxString(e.GetChainedMessage())); + } + catch (const std::exception &e) { + SHOW_EXCEPTION(wxString(e.what(), wxConvUTF8)); + } + catch (const wchar_t *e) { + SHOW_EXCEPTION(wxString(e)); + } + catch (const char *e) { + SHOW_EXCEPTION(wxString(e, wxConvUTF8)); + } + catch (const wxString &e) { + SHOW_EXCEPTION(e); + } +#undef SHOW_EXCEPTION +} + + + #if wxUSE_STACKWALKER == 1 /// @brief Called at the start of walking the stack. /// @param cause cause of the crash. diff --git a/aegisub/src/main.h b/aegisub/src/main.h index 7577c70f3..4e96c0d8f 100644 --- a/aegisub/src/main.h +++ b/aegisub/src/main.h @@ -88,8 +88,8 @@ public: /// DOCME FrameMain *frame; -#ifdef WITH_AUTOMATION +#ifdef WITH_AUTOMATION /// DOCME Automation4::AutoloadScriptManager *global_scripts; #endif @@ -115,6 +115,16 @@ public: void OnFatalException(); #endif +#if defined(wxUSE_EXCEPTIONS) + // This function wraps all event handler calls anywhere in the application and is + // our ticket to catch exeptions happening in event handlers. + virtual void HandleEvent(wxEvtHandler *handler, + wxEventFunction func, + wxEvent& event) const; +#else +# error wxWidgets is compiled without exceptions support, Aegisub requires exceptions support in wxWidgets to run safely +#endif + //int OnRun(); DECLARE_EVENT_TABLE() }; @@ -122,11 +132,7 @@ public: DECLARE_APP(AegisubApp) -//////////////// -// Stack walker #if wxUSE_STACKWALKER == 1 - -/// DOCME /// @class StackWalker /// @brief DOCME ///