Skip to content

Exception Translation

Philippe Marschall edited this page Oct 12, 2016 · 2 revisions

There different ways are provided how you can handle exceptions:

  • If the method declares throws SQLException no exception translation will happen and the original exception will be propagated.
  • If the does not method declare throws SQLException exception translation to an UncheckedSQLException will happen.
  • If the does not method declare throws SQLException exception and Spring is present translation will happen using Spring DataAccessException hierarchy.
  • should none of these meet your needs you can implement you own SQLExceptionAdapter

For example if your method looks like this

public interface TaxProcedures {

  BigDecimal salesTax(BigDecimal subtotal) throws SQLException;

}

then you will get the original SQLException. However if your method looks like this

public interface TaxProcedures {

  BigDecimal salesTax(BigDecimal subtotal); // no throws SQLException

}

you will get a UncheckedSQLException unless Spring is present. In that case you will get a DataAccessException or subclass.

Clone this wiki locally