forked from mia/Aegisub
Improve error reporting when an error occurs during startup
Originally committed to SVN as r4820.
This commit is contained in:
parent
c6f20504cb
commit
36a102e558
1 changed files with 43 additions and 38 deletions
|
@ -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,47 +317,50 @@ 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.");
|
||||||
|
|
||||||
|
static void UnhandledExeception(bool stackWalk) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
#if wxUSE_STACKWALKER == 1
|
||||||
|
if (stackWalk) {
|
||||||
|
StackWalker walker(_T("Fatal exception"));
|
||||||
|
walker.WalkFromException();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Inform user of crash.
|
||||||
|
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
|
/// @brief Called during an unhandled exception
|
||||||
void AegisubApp::OnUnhandledException() {
|
void AegisubApp::OnUnhandledException() {
|
||||||
// Current filename if any.
|
UnhandledExeception(false);
|
||||||
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.
|
/// @brief Called during a fatal exception.
|
||||||
void AegisubApp::OnFatalException() {
|
void AegisubApp::OnFatalException() {
|
||||||
// Current filename if any.
|
UnhandledExeception(true);
|
||||||
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);
|
|
||||||
|
|
||||||
#if wxUSE_STACKWALKER == 1
|
|
||||||
// Stack walk
|
|
||||||
StackWalker walker(_T("Fatal exception"));
|
|
||||||
walker.WalkFromException();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Inform user of crash
|
|
||||||
wxMessageBox(wxString::Format(exception_message, filename.c_str()), _("Program error"), wxOK | wxICON_ERROR | wxSTAY_ON_TOP, NULL);
|
|
||||||
}
|
}
|
||||||
#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
|
||||||
|
|
Loading…
Reference in a new issue