From 5a686c5460e9fbb32af5014d0dbf1169ea301ec2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 17 Mar 2017 12:40:02 +0200 Subject: Catch and dump unhandled exceptions in async task functions The problem with relying on noexcept for this is that there is no stack. --- build2/test/script/parser.cxx | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'build2/test/script/parser.cxx') diff --git a/build2/test/script/parser.cxx b/build2/test/script/parser.cxx index d004223..0555f2f 100644 --- a/build2/test/script/parser.cxx +++ b/build2/test/script/parser.cxx @@ -2867,6 +2867,26 @@ namespace build2 exec_scope_body (); } + static void + execute_impl (scope& s, script& scr, runner& r) noexcept + { + try + { + parser p; + p.execute (s, scr, r); + } + catch (const failed&) + { + s.state = scope_state::failed; + } + catch (const std::exception& e) + { + *diag_stream << "unhandled exception: " << e; + assert (false); + abort (); + } + } + void parser:: exec_scope_body () { @@ -2983,20 +3003,13 @@ namespace build2 // bail out if we weren't asked to keep going. // if (!sched.async (task_count, - [] (scope& s, script& scr, runner& r, + [] (scope& s, + script& scr, + runner& r, const diag_frame* ds) noexcept { diag_frame df (ds); - - try - { - parser p; - p.execute (s, scr, r); - } - catch (const failed&) - { - s.state = scope_state::failed; - } + execute_impl (s, scr, r); }, ref (*chain), ref (*script_), -- cgit v1.1