Exceptions question
Posted: Sun Dec 17, 2006 10:14 pm
Hello,
This is such a n00b question, I feel ashamed asking given my post count here at devnetwork. Nevertheless, I got into OOP now (joined the dark side, so to speak
), and there's one thing I cannot understand, and that's exceptions. I will use an example of a user ID getting passed through $_GET and checking against the database for whether or not that user exists. How is the throw...try...catch different from doing something like this:
Can someone please walk me through doing the same thing in throw...try...catch and tell me how it is superior?
Thank you and happy holidays!
This is such a n00b question, I feel ashamed asking given my post count here at devnetwork. Nevertheless, I got into OOP now (joined the dark side, so to speak
Code: Select all
$userid = $_GET['userid'];
if (is_valid($userid)){ //where is_valid is a custom method that returns true if the user exists and false if he doesn't
$user = new User ($userid);
}
else{
echo "mistake in userid";
}Thank you and happy holidays!