File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Exception handling in J2EE layered projects- Best practices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Exception handling in J2EE layered projects- Best practices" Watch "Exception handling in J2EE layered projects- Best practices" New topic
Author

Exception handling in J2EE layered projects- Best practices

chets patel
Ranch Hand

Joined: Apr 27, 2010
Posts: 74

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
chets patel
Ranch Hand

Joined: Apr 27, 2010
Posts: 74

No body is there to answer my question
Please help if any one knows the ans
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception handling in J2EE layered projects- Best practices