Exception handling

Hello, does anyone know good web resources (articles, web pages, whatever) where the "proper" Exception handling is explained, specifically when coding against database? Something like "best practices" in Exception handling. I am writing server component of the application which is manipulating the db. Requests for db manipulation will come from the clients via Servlets, and my component will be sending them Responses. I was only able to find introductions or EJB specific articles. What I am after is a real-life Exception handling policies for JDK and JDBC. Regards, branko.

I dont any resources, but general rule of thumb: 1. Always catch SQLException (obviously) and rollback transaction 2. Always close resultset, statement and connection in finally block - use separate methods to close them Ex: finally {

Branko, I wouldn't go so far as to say that the following is a "best practices" - but if you are looking for free information that is clear on Exception Handling you might want to check out: Bradley Kjell's Beginning Java course - chapter 80. You'll want to look at Chapter 81, too. This link at IBM goes into the finally keyword which may be of some help, too:Using Finally to avoid resource links Of course, there is always the Sun site which is pretty good in the area of JDBC. These few links might help you out: JDBC 2.0 FundamentalsAdv Tutorial on JDBCJDBC API Tutorial and Reference Good Luck! Janet [ November 12, 2002: Message edited by: Janet Wilson ] [ November 12, 2002: Message edited by: Janet Wilson ]

Branko Paskutini
Greenhorn

Joined: Apr 18, 2002
Posts: 25

posted Nov 12, 2002 17:18:00

0

Thank you Janet and Anand. I didn't mean to scare anyone with my 'best practices' statement, I just thought that would better explain what I am after. Come to think of it, ANY practices would do. I will be closing all the resources in the 'finally' block, but the difficult part for me is what to do within the 'catch', apart from logging it (will most likely use Log4J). I read about the exception chaining, seems like a good start.http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-exceptions-p2.html