tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohun Biswas <>
Subject translating exceptions
Date Fri, 25 Jul 2003 12:08:43 GMT
This feels like something that would come up often but, not being a Java 
guru, I'm not sure of the solution. I have a web app with a number of 
servlets accessing a database via JDBC. I encapsulate all the JDBC work 
within a class called JDBCAccess. In order to allow code to be tested from 
the command line (or from other non-servlet-engine environments) I don't 
want JDBCAccess to use any javax.servlet.* classes. Thus encapsulation is 
strict both ways: the servlets don't use any java.sql.* classes (directly) 
and the database code doesn't use any javax.servlet.* classes.

This works fine with one irritating little problem: since each JDBCAccess 
method can throw SQLException,  each use of them within a servlet must do a 
boilerplate try/catch in order to re-throw it as ServletException, e.g.

	try {
	} catch (SQLException e) {
		throw new ServletException(e);

I can't declare my servlets to throw SQLException, partly because I don't 
want to and of course because the spec doesn't allow it anyway. Is there a 
simpler way? Can I maybe define my own exception class to "translate" 
between SQLException and ServletException, and if so what would that look 
like? Would it inherit from ServletException or SQLException?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message