This is more of a design question and i was hoping to get pros and opinions on what makes sense.
Imagine something that holds one or more event listeners. Every now and then the thing fires events to its listeners.
The problem is of course that listeners that follow after a listener that throws never get to know about the event. THis means that the order of listeners thus is an issue.
Execute all listeners catching any thrown exceptions. This means all listeners are fired but in itself introduce other problems.
What should be done with caught exceptions ?
- One option is to catch them all and after firing all events throw another exception which holds all the problems. ++
- The other option is to log ~~
- The last is to simply ignore these exceptions. --
- Listeners are executed in isolation which is good. ++
This option is the simplist and simply lets any thrown exception from a listener escape, resulting in remaining listeners never getting fired. Problems with this approach mean that
- the order of listeners is significant(-)
- simple to implement(+).
- before listeners can affect the caller
Which approach makes sense and causes the least number of problems. Does it really make sense to isolate listeners so they get events but cannot cause a running operation to abort if they throw ?