Results 1 to 3 of 3

Thread: Checked vs unchecked exception

  1. #1
    Join Date
    Sep 2004
    Location
    France
    Posts
    44

    Default 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. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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?
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Sep 2004
    Posts
    1

    Default

    Quote 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

Similar Threads

  1. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  2. Replies: 0
    Last Post: Jul 11th, 2005, 05:49 PM
  3. Downgrading RuntimeException to Checked Exception
    By matthewdfleming in forum Data
    Replies: 4
    Last Post: Apr 8th, 2005, 12:42 AM
  4. Replies: 2
    Last Post: Dec 20th, 2004, 04:35 PM
  5. Replies: 3
    Last Post: Nov 8th, 2004, 07:30 PM

Posting Permissions

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