SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Dec 4, 2009, 08:10 #1
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.htmlMy project: Open source Q&A
(similar to StackOverflow)
powered by php+MongoDB
Source on github, collaborators welcome!
-
Dec 4, 2009, 08:18 #2
- 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.
-
Dec 4, 2009, 08:32 #3
Thank you.
My project: Open source Q&A
(similar to StackOverflow)
powered by php+MongoDB
Source on github, collaborators welcome!
-
Dec 4, 2009, 09:07 #4
- 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!
-
Dec 4, 2009, 09:08 #5My project: Open source Q&A
(similar to StackOverflow)
powered by php+MongoDB
Source on github, collaborators welcome!
Bookmarks