Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Exception handling (Dao or Service ?)

  1. #11
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I agree with your first approach of originating the exception in the service. IMHO, DAO's should be as dumb as possible, and only throw exceptions that are related to either a bad argument (IllegalArgumentException) or thier *specific* implementation. i.e. SqlExceptions if using straight sql, etc. The problem with throwing your checked exception from the dao, is that it's specific to a domain concern, someone is trying to save an existing user, and you want to catch the exception and recover. If this domain concern is left to the dao, someone wanting to add a new dao implementation also has to worry about whatever domain concerns the dao is supposed to provide PLUS it's actual data access requirements.

    I view the actual service as the Repository, it's implementing the Domain concerns and calling DAOs to defer the actual data access.

  2. #12
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by lucasward View Post
    If this domain concern is left to the dao, someone wanting to add a new dao implementation also has to worry about whatever domain concerns the dao is supposed to provide PLUS it's actual data access requirements.
    I would agree, that's actually a better way of looking at it and explaining it .
    Last edited by karldmoore; Aug 30th, 2007 at 06:12 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #13
    Join Date
    Jul 2005
    Posts
    156

    Default

    Thank you - really. I'm now sure to have a consistent approach for my exception handling.

    Moreover, I can now connect the DDD Repository principle with the traditional layers (don't know why I was so sure in my mind Repository = Dao).

  4. #14

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •