In a previous post, I wrote about how to centralize java exception handling inside one method by saving the exception to a local variable. Some of you might ask, "why not put exception logic into a separate private method?" I would avoid this approach for the following reasons:
1. When the exception-handling logic is specific to the current method, I like to scope it to the current method. Even if we have a
private void handleException, it can still be called by other methods in the current class.
2. With a private exception-handling method, you will need to pass in all the info needed for handling the exception, in addition to the
Exception. In addition, what info is needed may change overtime. This may lead to methods like this:
private void handleException(Exception e, String name, String info)