wesnoth/wesnoth — pull request #191 by cbeck88 (2014-06-05 01:06:32+00:00)
Title: Fixup exceptions in playcontroller

This sequence of commits attempts to refactor the engine so that at least the play controller engine does not use "end_level_exception" and "end_turn_exception" for normal control flow. This helps us to simplify the normal working of the engine and make it less opaque, and might help us to safely use RAII objects for networking at least for normal purposes.

The first step is to introduce an appropriate type "possible_end_play_signal",
which covers both end_level_exception and end_turn_exception. This is intended
to become the return value of void member functions of play_controller which
previously would throw these exceptions up the call stack.

The first commit also introduces macros which make it easy to catch the exceptions,
convert them to the signal type, and return, and also to propogate the returned
signal to the caller.

The subsequent commits work from the root, at play_controller::play_scenario,
wrapping possible exception sources and handling the signal type instead. We
work incrementally, testing at each step to avoid breaking anything. Once
a function has been converted, we can work to convert the functions it calls,
and then switch calls to those functions from being wrapped in the "HANDLE"
macro to being wrapped in the "PROPOGATE" macro which is much cheaper
than an exception throw and doesn't carry the dangers of crashing the program
if a destructor somewhere throws an exception.

I suppose that if we continue this way, we could push all the throws into the
event handler and the replay module. Perhaps could continue from there,
but likely at some point the exceptions might be the simpler solution esp.
for breaking recursion in WML / lua or things like this.