try..catch is needed only if the operation //can have a duplicate problem try { dao.addSomething(); } catch (DuplicateException ex){ addError("Cannot add. That item already exists."); } }
Note that if the operation cannot have a duplicate problem, then the Action should not attempt to catch DuplicateException.
Here is the DAO operation which may have a duplicate problem.
//It is highly recommended, but optional, to declare //DuplicateException in this method header, to bring //it to the attention of the caller public addSomething() throws DAOException, DuplicateException { //...elided }
Again, if the operation cannot have a duplicate problem, then the DAO should not declare a
DuplicateException in its throws clause.
The {@link Db#add(SqlId,Object[])} and {@link Db#edit(SqlId,Object[])} methods can throw a DuplicateException.