[wesnoth-commits] [wesnoth/wesnoth] 874699: GUI2/Loading Screen: handle throwing exceptions fr...

Charles Dang noreply at github.com
Wed Oct 7 10:19:30 UTC 2020


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth
  Commit: 87469933bc4877261922baf2a3a6c56eb54a8508
      https://github.com/wesnoth/wesnoth/commit/87469933bc4877261922baf2a3a6c56eb54a8508
  Author: Charles Dang <exodia339 at gmail.com>
  Date:   2020-10-07 (Wed, 07 Oct 2020)

  Changed paths:
    M src/gui/dialogs/loading_screen.cpp
    M src/gui/dialogs/loading_screen.hpp

  Log Message:
  -----------
  GUI2/Loading Screen: handle throwing exceptions from the future

Despite having exception handing in process(), the loading screen is only designed to handle one exception from the worker.
If such an exception propagates to the worker, the loading screen would rethrow it in process(). It turns out we don't need
an exception_ptr, since the exception would already be stored in the future returned from std::async. Fetching it with get()
causes it to be rethrown at that point, same as before.

Do note we do not want to simply call get() and wait, since that essentially calls future::wait() instead of future::wait_for()
and would halt the main thread while it waits for the worker. Hence, we still manually check its status before fetching the
exception (if any). As a bonus, it means we can use future::valid() as a check for whether the worker is still running in the
dtor, since calling get() sets future::valid() to false. Any premature exit of the loading screen after the worker thread is
created or its exception is handled in the finally process() loop will trigger the safe_exit call.





More information about the Commits mailing list