
Originally Posted by
Rod Johnson
Why not catch the DataAccessException subclasses you can recover or retry in the DAO layer? Or business layer? DataAccessException provides an informative hierarchy to facilitate this.
Now,I write a class that extends DataAccessException. For example:
Code:
public class MyDataAccessException extends DataAccessException{
.................................
}
public class YourDataAccessException extends DataAccessException{
.................................
}
In servlet , I can do it in this way:
Code:
public class myServlet extends HttpServlet{
public void doPost(.......................)....{
try{
mydao.getList();
}catch(MyDataAccessException myex){
//do something
}catch(YourDataAccessException yourex){
//do something
}
Or in this way:
Code:
public void doPost(.......................)....{
try{
mydao.getList();
}catch(Exception myex){
if(myex instanceof MyDataAccessException){
//do something
}
}catch(YourDataAccessException yourex){
if(yourex instanceof YourDataAccessException){
//do something
}
}
That what you mean? It is right method to do this? I mean that I could catch DataAccessException thought it is runtimeException?