Hi everyone:
I want to know how to process Exception in DAO layer. For example.there are two method to do this:
one method:
Code:
public class PersonDAOImpl implements PersonDAO{
public void updatePerson(Person p){
...........................................
try{
session.update(p);
tx.commit();
}catch(HibernateException ex){
tx.rollback();
ex.printStackTrace();
}finally{
session.close();
}
....................................
Two method:
Code:
public void updatePerson(Person p){
...........................................
try{
session.update(p);
tx.commit();
}catch(HibernateException ex){
throw new MyException("HibernateEx");
}
If I use the first one,I can't catch the Exception in Servlet ,So I can't send redirect to the specific error page.
Which is better ? Shoud I process exception in DAO Layer or web layer? Thks!