Hi All,
I read lots of posts regarding exception handling in
J2EE projects and learnt following points.
1. Method signature should throw only checked exception
2. We need to catch the checked exception and rethrow runtime exception by wrapping it.
3. Logging should be done only once for any exception.
These may be very simple points for you but I am very much confused. I have following doubts. It would be great if you clarify my doubts.
1. Suppose I am using spring and I want to handle DataAccessException(Which is runtime exception) in service layer
a) should I do catch(DataAccessException e) in my service layer
If Yes: Many people say that you do not need to catch runtime exception.
If No: How will I handle it in my application if such exception occurs. Is it good practice to propagate my DataAccessException till Action layer?
b) on what basis I should convert the checked exception into uncheked exception(referencing to point 2 above). It would be better if you can provide any example.
c) How to handle run time exceptions if I am not supposed to catch runtime exception. Somewhere I have to catch the runtime exception
I know that many times it is dependent on the requirements from the customer, but I just want to know about best practices about exception handling.
Thanks in advance