diff --git a/aegisub/src/main.cpp b/aegisub/src/main.cpp index e811f642e..229783595 100644 --- a/aegisub/src/main.cpp +++ b/aegisub/src/main.cpp @@ -383,8 +383,10 @@ void AegisubApp::OnFatalException() { UnhandledExeception(true, frame ? frame->context.get() : nullptr); } +#define SHOW_EXCEPTION(str) \ + wxMessageBox(wxString::Format(_("An unexpected error has occurred. Please save your work and restart Aegisub.\n\nError Message: %s"), str), \ + "Exception in event handler", wxOK | wxICON_ERROR | wxCENTER | wxSTAY_ON_TOP) void AegisubApp::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& event) const { -#define SHOW_EXCEPTION(str) wxMessageBox(str, "Exception in event handler", wxOK | wxICON_ERROR | wxCENTER | wxSTAY_ON_TOP) try { wxApp::HandleEvent(handler, func, event); } @@ -400,9 +402,35 @@ void AegisubApp::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEven catch (const wxString &e) { SHOW_EXCEPTION(e); } -#undef SHOW_EXCEPTION + catch (...) { + SHOW_EXCEPTION("Unknown error"); + } } +bool AegisubApp::OnExceptionInMainLoop() { + try { + throw; + } + catch (const agi::Exception &e) { + SHOW_EXCEPTION(to_wx(e.GetChainedMessage())); + } + catch (const std::exception &e) { + SHOW_EXCEPTION(to_wx(e.what())); + } + catch (const char *e) { + SHOW_EXCEPTION(to_wx(e)); + } + catch (const wxString &e) { + SHOW_EXCEPTION(e); + } + catch (...) { + SHOW_EXCEPTION("Unknown error"); + } + return true; +} + +#undef SHOW_EXCEPTION + int AegisubApp::OnRun() { std::string error; diff --git a/aegisub/src/main.h b/aegisub/src/main.h index aafda6e2f..622dccd46 100644 --- a/aegisub/src/main.h +++ b/aegisub/src/main.h @@ -51,6 +51,7 @@ class AegisubApp: public wxApp { void OnUnhandledException() override; void OnFatalException() override; + bool OnExceptionInMainLoop() override; /// @brief Handle wx assertions and redirect to the logging system. /// @param file File name