27.10.2013 Views

Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird

Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird

Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3. Handling exceptions<br />

Chapter 3.<br />

An exception handling is probably the most important aspect that directly affects<br />

the stability of the application. Correct handling of the error cases guarantees<br />

correct functioning of the client code as well as the database server. Additionally,<br />

all methods of the interfaces defined in the <strong>JDBC</strong> specification throw instances of<br />

java.sql.SQLException to notify about all error conditions that happen during<br />

request processing. The SQLException is checked exception, which forces <strong>Java</strong><br />

programmer to either handle it with the try/catch clause or redeclare it in the<br />

method signature.<br />

Working with exceptions<br />

The exception handling becomes even more important if we consider that this<br />

topic is either ignored or presented in incorrect form in the most <strong>JDBC</strong> tutorials.<br />

The official <strong>JDBC</strong> tutorial from Sun Microsystems briefly mentions that<br />

exceptions should be handled by using try/catch blocks only at the end of the<br />

course, but neither reasons of doing this nor the best practices are presented.<br />

There are few reasons to think about exception handling in your applications<br />

before you start coding. First of all, it is very hard to change the exception<br />

handling pattern in the existing code. The changes will affect all layers above the<br />

place where the changes in exception handling are made and the new application<br />

must be thoroughly tested after the change.<br />

Another reason was already mentioned on the beginning of this chapter –<br />

instances of java.sql.SQLException is the only way for the RDBMS server to<br />

notify about the error condition that happened during request processing. By

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!