Define application-level exception handler of last resort.
This commit is contained in:
parent
40e73cdcdd
commit
a1bc6948f4
|
@ -60,6 +60,7 @@ It handles initialization and termination by subclassing wxApp.
|
|||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "AudacityException.h"
|
||||
#include "AudacityLogger.h"
|
||||
#include "AboutDialog.h"
|
||||
#include "AColor.h"
|
||||
|
@ -1084,6 +1085,47 @@ void AudacityApp::OnFatalException()
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
bool AudacityApp::OnExceptionInMainLoop()
|
||||
{
|
||||
// This function is invoked from catch blocks in the wxWidgets framework,
|
||||
// and throw; without argument re-throws the exception being handled,
|
||||
// letting us dispatch according to its type.
|
||||
|
||||
try { throw; }
|
||||
catch ( AudacityException &e ) {
|
||||
// Here is the catch-all for our own exceptions
|
||||
|
||||
// Use CallAfter to delay this to the next pass of the event loop,
|
||||
// rather than risk doing it inside stack unwinding.
|
||||
auto pProject = ::GetActiveProject();
|
||||
std::shared_ptr< AudacityException > pException { e.Move().release() };
|
||||
CallAfter( [=] // Capture pException by value!
|
||||
{
|
||||
|
||||
// Restore the state of the project to what it was before the
|
||||
// failed operation
|
||||
pProject->RollbackState();
|
||||
|
||||
pProject->RedrawProject();
|
||||
|
||||
// Give the user an alert
|
||||
pException->DelayedHandlerAction();
|
||||
|
||||
} );
|
||||
|
||||
// Don't quit the program
|
||||
return true;
|
||||
}
|
||||
catch ( ... ) {
|
||||
// There was some other type of exception we don't know.
|
||||
// Let the inherited function do throw; again and whatever else it does.
|
||||
return wxApp::OnExceptionInMainLoop();
|
||||
}
|
||||
|
||||
// Shouldn't ever reach this line
|
||||
return false;
|
||||
}
|
||||
|
||||
#if defined(EXPERIMENTAL_CRASH_REPORT)
|
||||
void AudacityApp::GenerateCrashReport(wxDebugReport::Context ctx)
|
||||
{
|
||||
|
|
|
@ -63,6 +63,7 @@ class AudacityApp final : public wxApp {
|
|||
bool OnInit(void) override;
|
||||
int OnExit(void) override;
|
||||
void OnFatalException() override;
|
||||
bool OnExceptionInMainLoop() override;
|
||||
|
||||
int FilterEvent(wxEvent & event);
|
||||
|
||||
|
|
Loading…
Reference in New Issue