I have developed a framework which allows other people to plug-in different implementations of optimizers. These optimizers are run asynchronously and I have attached listeners to run before and after inside the asynchronous code to monitor the execution of the optimizer. For example:
public void async(Optimizer o){
runListeners(o);
o.run();
runListeners(o);
}
My problem is that some lazy programmer is throwing a some NullPointerExceptions inside their code and preventing the method from executing the listeners for the second time. I thought about catching RuntimeException but this feels wrong to me.
Any time you create a framework for plugins to run you have to consider how to handle exceptions thrown by the plugins, because you usually don’t want a badly behaved plugin to crash your whole program. There is nothing wrong with catching Exception, RuntimeException, or maybe even Throwable here (though an Error might still be cause for aborting).