Improve error reporting when an error occurs during startup

Originally committed to SVN as r4820.
This commit is contained in:
Thomas Goyne 2010-10-20 00:28:37 +00:00
parent c6f20504cb
commit 36a102e558

View file

@ -87,13 +87,14 @@ namespace config {
// wxWidgets macro // wxWidgets macro
IMPLEMENT_APP(AegisubApp) IMPLEMENT_APP(AegisubApp)
static const wchar_t *LastStartupState = NULL;
#ifdef WITH_STARTUPLOG #ifdef WITH_STARTUPLOG
/// DOCME /// DOCME
#define StartupLog(a) MessageBox(0, a, _T("Aegisub startup log"), 0) #define StartupLog(a) MessageBox(0, a, _T("Aegisub startup log"), 0)
#else #else
#define StartupLog(a) #define StartupLog(a) LastStartupState = a
#endif #endif
#ifdef __VISUALC__ #ifdef __VISUALC__
@ -316,27 +317,8 @@ int AegisubApp::OnExit() {
/// Message displayed when an exception has occurred. /// Message displayed when an exception has occurred.
const static wxString exception_message = _("Oops, Aegisub has crashed!\n\nAn attempt has been made to save a copy of your file to:\n\n%s\n\nAegisub will now close."); const static wxString exception_message = _("Oops, Aegisub has crashed!\n\nAn attempt has been made to save a copy of your file to:\n\n%s\n\nAegisub will now close.");
/// @brief Called during an unhandled exception static void UnhandledExeception(bool stackWalk) {
void AegisubApp::OnUnhandledException() { if (AssFile::top) {
// Current filename if any.
wxFileName file(AssFile::top->filename);
if (!file.HasName()) file.SetName(_T("untitled"));
// Set path and create if it doesn't exist.
file.SetPath(StandardPaths::DecodePath(_T("?user/recovered")));
if (!file.DirExists()) file.Mkdir();
// Save file
wxString filename = wxString::Format("%s/%s_%s.ass", file.GetPath(), wxDateTime::Now().Format("%Y-%m-%d-%H%M%S"), file.GetName());
AssFile::top->Save(filename,false,false);
// Inform user of crash.
wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR, NULL);
}
/// @brief Called during a fatal exception.
void AegisubApp::OnFatalException() {
// Current filename if any. // Current filename if any.
wxFileName file(AssFile::top->filename); wxFileName file(AssFile::top->filename);
if (!file.HasName()) file.SetName(_T("untitled")); if (!file.HasName()) file.SetName(_T("untitled"));
@ -350,13 +332,35 @@ void AegisubApp::OnFatalException() {
AssFile::top->Save(filename,false,false); AssFile::top->Save(filename,false,false);
#if wxUSE_STACKWALKER == 1 #if wxUSE_STACKWALKER == 1
// Stack walk if (stackWalk) {
StackWalker walker(_T("Fatal exception")); StackWalker walker(_T("Fatal exception"));
walker.WalkFromException(); walker.WalkFromException();
}
#endif #endif
// Inform user of crash // Inform user of crash.
wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR | wxSTAY_ON_TOP, NULL); wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR, NULL);
}
else if (LastStartupState) {
#if wxUSE_STACKWALKER == 1
if (stackWalk) {
StackWalker walker(_T("Fatal exception"));
walker.WalkFromException();
}
#endif
wxMessageBox(wxString::Format("Aegisub has crashed while starting up!\n\nThe last startup step attempted was: %s.", LastStartupState), _("Program error"), wxOK | wxICON_ERROR);
}
}
/// @brief Called during an unhandled exception
void AegisubApp::OnUnhandledException() {
UnhandledExeception(false);
}
/// @brief Called during a fatal exception.
void AegisubApp::OnFatalException() {
UnhandledExeception(true);
} }
#endif #endif
@ -472,9 +476,10 @@ int AegisubApp::OnRun() {
} }
// Catch errors // Catch errors
catch (wxString &err) { error = err; } catch (const wxString &err) { error = err; }
catch (wxChar *err) { error = err; } catch (const wxChar *err) { error = err; }
catch (std::exception &e) { error = wxString(_T("std::exception: ")) + wxString(e.what(),wxConvUTF8); } catch (const std::exception &e) { error = wxString(_T("std::exception: ")) + wxString(e.what(),wxConvUTF8); }
catch (const agi::Exception &e) { error = "agi::exception: " + lagi_wxString(e.GetChainedMessage()); }
catch (...) { error = _T("Program terminated in error."); } catch (...) { error = _T("Program terminated in error."); }
// Report errors // Report errors