I call a lot of outside functions from within my state machine - either explicitly like sendMessage(...)
or implicitly like a!=b
. So far I have tried to keep track of what can throw, but as the number grows so does the need for a better method. Missing an exception and allowing it to propagate into the state machine framework's code would obviously cause a lot of mayhem.
I see three options but I hope someone can point me to a better one:
Put a
try catch
at eachonEntry
,onExit
andaction
. Since there are many of them and they are pretty shot, this would almost double the length of code and decrease readability.Make a whole lot of functions
noexcept
. This seems impossible in cases where the function is used somewhere else, or where it can legitimately throw and the exception is the only good solution.Modify most of the functions I call to use alexandrescu's
Expected<T>
as a return type. See: http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandrescu-Systematic-Error-Handling-in-C
Which option is best? Is there an even better strategy?