java - Where to handle exception whether in DAO layer or Delegate layer? -


for better designing application:

  1. where handle exception whether in dao layer or delegate layer?
  2. which 1 better approach out of 2 given in 1?

as usual "design" questions: depends.

in general, handle many exceptions possible locally, in case in dao, may want re-throw exceptions or raise new ones directly.

e.g. if dao causes sqlexception, not want let upper layers know sql used, catching exception on advisable (so don't have import sqlexception in delegate layer's package). however, re-throwing sqlexception inside mycustomdaoexception allow retain error information.

tldr; in dao, , throw new exceptions containing original 1 if needed.


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -