Centralize exception handling in java methods (2)

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)
throws AppException


Unknown said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Unknown said...

Thanks for sharing this informative information.You may also refer.....Exception handling in java An exception or exceptional event is a problem that arises during the execution of a program..

Capri said...

You wrote it so well.

eMexoT said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Internet Of Things training in electronic city