5

Is there some way to override the specific moment when a slot is called in boost::signals2 and perform some actions (logging, debugging, exception handling)?

I would like to catch exceptions at the moment of slot invocations, because signals/slots are where the execution path in my code crosses between various software components and each component is meant to be optional / can be disabled at run-time if it misbehaves. So when a slot invocation throws (might come from an external library, might just be std::bad_alloc), I would like to be notified about it -- and know which component was signaled into -- so I can kill that component.

I don't see how I can do it in a combiner because I don't have access to the slot or connection objects there? So I don't see a way to get any information. (Changing the return type on every slot is unfeasible.)

Is there some super easy way to do this that I've missed?

If not, how should I go about it?

Subclass something like slot_call_iterator (to wrap call in try/catch) and connection_body_base (to store information about what component it belongs to for example) and have boost use these? (How?)

Or subclass signals2::slot<...>, give it information about the owning component in the constructor and somehow overload the operator()(...)? (No idea about that either, seems way harder with all the template magic.)

integer
  • 1,075
  • 7
  • 12
  • 1
    Such a functionality doesn't seem to exist, but you can add a feature request in the trac (or even provide a patch). – Igor R. Jun 10 '13 at 08:15
  • Thank you for your comment. Yeah, I assumed it didn't exist, was just wondering if there were a way to subclass or override publicly exported boost classes to make my own, sort of. It can be intimidating trying to do this blindly with boost code as I'd fear doing something which might break or misuse internals. – integer Jul 10 '13 at 17:52

1 Answers1

0

To summarize the comments:

From Igor R.

Such a functionality doesn't seem to exist, but you can add a feature request in the trac (or even provide a patch).

From integer (nice nickname):

Thank you for your comment. Yeah, I assumed it didn't exist, was just wondering if there were a way to subclass or override publicly exported boost classes to make my own, sort of. It can be intimidating trying to do this blindly with boost code as I'd fear doing something which might break or misuse internals.

YesThatIsMyName
  • 1,585
  • 3
  • 23
  • 30