Add wxApp::StoreCurrentException() and RethrowStoredException().

These methods can be used to ensure that the exceptions thrown from event
handlers are safely rethrown from the code dispatching the events once the
control flow gets back there.

This allows to work around the problem with not being able to propagate
exceptions through non-C++ code and can be used, for example, to catch
exceptions thrown by the handlers invoked from inside wxYield() by a try/catch
block around wxYield() -- something that didn't work before, update the except
sample to show that it does work now.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77468 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-08-24 15:31:44 +00:00
parent c779385a1a
commit 1cecee5bb7
9 changed files with 333 additions and 22 deletions

View File

@@ -140,6 +140,14 @@ bool wxEventLoopBase::YieldFor(long eventsToProcess)
DoYieldFor(eventsToProcess);
// If any handlers called from inside DoYieldFor() threw exceptions, they
// may have been stored for later rethrow as it's unsafe to let them escape
// from inside DoYieldFor() itself, as it calls native functions through
// which the exceptions can't propagate. But now that we're back to our own
// code, we may rethrow them.
if ( wxTheApp )
wxTheApp->RethrowStoredException();
return true;
}
@@ -207,7 +215,15 @@ bool wxEventLoopManual::ProcessEvents()
if ( m_shouldExit )
return false;
}
return Dispatch();
const bool res = Dispatch();
// Rethrow any exceptions which could have been produced by the handlers
// ran by Dispatch().
if ( wxTheApp )
wxTheApp->RethrowStoredException();
return res;
}
int wxEventLoopManual::DoRun()