Announcement Announcement Module
Collapse
No announcement yet.
Checked vs unchecked exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checked vs unchecked exception

    I have a rule that says that my password must be more that 4 characters. So in my User domain object I have to check this in the setPassword method.

    If the rule is broken I throw an exception. I can't decide wether I throw a checked or unchecked exception in this case. Can somebody advise me ?

    It's an exception the caller can handle so Rod's book advise to throw a checked exception. But if I do that, lot of my setters will throw exception and this may lead in a lot of unnecessary catch blocks.

    Thanx

    Seb

  • #2
    If you want to keep the validation in the domain object I would make the exception checked. An alternative might be to remove the syntactic validation from the domain object into a validator.

    I don't understand why using a checked exception would impact so many setters--in how many places do you set the password property?

    Comment


    • #3
      Originally posted by Rod Johnson
      I don't understand why using a checked exception would impact so many setters--in how many places do you set the password property?
      No, I mean that I have thus kind of validation (non null, max size, format) in all my setters so all the classes that use my domain objects have to deal with this kind of exceptions. I am thinking of creating a DomainCheckException and all setters will throw some subclasses of this exception

      Comment

      Working...
      X