boostorg / msm

Boost.org msm module
http://boost.org/libs/msm
29 stars 53 forks source link

Adding a return value to "exception_caught" #76

Open davidfrulm opened 1 month ago

davidfrulm commented 1 month ago

How feasible would be to add a return value to "exception_caught" so that we could decide if event is actually considered "handled"?

template <class StateMachine, class Event> HandledEnum exception_caught(Event const& event, StateMachine& stateMachine, std::exception const& e) { ... }

That would allow clients to custom define how to treat exceptions for certain events.

henry-ch commented 1 month ago

It is a good idea and it would have been very feasible if I had thought about that in the first place. So now, I cannot change it without breaking existing code (C++ functions cannot be overloaded only on return type) so all I can think of is adding a new version: template <class StateMachine, class Event> HandledEnum exception_caught_return(Event const& event, StateMachine& stateMachine, std::exception const& e) { ... } and then you could add a config flag in your concrete instance with typedef or using: typedef int use_exception_caught_with_return; Not very beautiful though. You also would have to use it for all events because you cannot partially specialize a function. Would that work for you?