Earlier quoted context omitted.
Can you describe your ideal error handling mechanisms? Or at least other mechanisms that feel more correct?
I would go with the Erlang approach. Just die FFS. Let the process monitor restart you if you deserve to live.
template
auto CallWithSupervision(Fn fn) -> decltype(fn()) {
// supervision loop
// configure conditions as needed
while(true) {
try {
return fn();
}
catch(std::exception& e) {
// log failure details
}
catch(...) {
// optional: exceptions out of handled set?
// kill supervisor.
throw;
}
}
}
//elsewhere
CallWithSupervision([relevant=state,&nd=captures]() { return Client(relevant, nd); });
Modify as you see fit. It's the simplest, synchronous Erlang supervisor, in C++. And it will already work with your code - exception handling is very composable this way.