SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What Exception class to use for this?

    Hello!
    I am rewrite a class I wrote a while ago to handle bounced emails.
    The bounce extractor is a 2 part process, first is to setup email server to forward bounce emails to a php script. I've done that already and it extracts
    bounced email data and records into xml file.

    The second part is from any php script you can access that xml file and check if node with email address exists in it.

    I am validating the 'email' param, and it must be a valid email address, so I'm using this:

    public function getBounceData($email){
    if(false === filter_var($email, FILTER_VALIDATE_EMAIL)){
    throw new Exception($email. ' is not a valid email address');
    }

    }

    // rest of the method

    }

    I want the exception to be of a more specific SPL Exception class. I don't want to define any extra exception class, so I want to use some SPL Exception

    I am wondering which one is more appropriate:
    InvalidArgumentException OR UnexpectedValueException
    or maybe some other one from this list:
    http://www.php.net/~helly/php/ext/sp...Exception.html
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    As the UnexpectedValueException is a RuntimeException, I'd go for the InvalidArgumentException.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  4. #4
    SitePoint Guru
    Join Date
    Jan 2005
    Location
    heaven
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You aren't limited to the to using the predefined exception classes. If you want, you can create your own
    Creativity knows no other restraint than the
    confines of a small mind.
    - Me
    Geekly Humor
    Oh baby! Check out the design patterns on that framework!

  5. #5
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by imaginethis View Post
    You aren't limited to the to using the predefined exception classes. If you want, you can create your own
    No kidding!
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!


Bookmarks

Posting Permissions

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