Pass exceptions in async workers back to the main thread

This commit is contained in:
Thomas Goyne 2014-05-09 06:30:07 -07:00
parent 74e995b915
commit eadf555da3
2 changed files with 28 additions and 15 deletions

View File

@ -91,7 +91,15 @@ void Init(std::function<void (Thunk)> invoke_main) {
}
void Queue::Async(Thunk thunk) {
DoInvoke(thunk);
DoInvoke([=] {
try {
thunk();
}
catch (...) {
auto e = std::current_exception();
invoke_main([=] { std::rethrow_exception(e); });
}
});
}
void Queue::Sync(Thunk thunk) {

View File

@ -152,8 +152,13 @@ bool AegisubApp::OnInit() {
wxTheApp->QueueEvent(evt);
});
wxTheApp->Bind(EVT_CALL_THUNK, [](wxThreadEvent &evt) {
evt.GetPayload<std::function<void()>>()();
wxTheApp->Bind(EVT_CALL_THUNK, [this](wxThreadEvent &evt) {
try {
evt.GetPayload<std::function<void()>>()();
}
catch (...) {
OnExceptionInMainLoop();
}
});
config::path = new agi::Path;