* Tularis <[EMAIL PROTECTED]>: > Matthew Weier O'Phinney wrote: > >> * Curt Zirzow <[EMAIL PROTECTED]>: >> >>>* Thus wrote Matthew Weier O'Phinney: >>> >>>>The problem I'm running into: what do I pass as arguments to catch()? >>>>The articles on ZE2 use something like: catch (Exception $e) {}, or >>>>something like catch(MyException $e) (where MyException is a class they >>>>defined in their examples). Is the 'Exception' class a base >>>>class/handler with PHP5? Do I need to create my own exception handler >>>>classes? Do I even need to catch objects of a specific type, or can I >>>>simply do: >>>> catch ($error) { >>>> do something with $error >>>> } >>> >>>At minimum you should always at least catch the Exception class: >>> >>> catch (Exception $e) { } >> >> >> So, the Exception class is in the PHP5 distribution, then? Do I need to >> include/require it, or is it implicit in simply running PHP5? >> >> <snip>
<snip> >> Next question: do I have to 'throw' an error for it to be caught? Again, >> coming from perl, if I try to eval something and it fails, I don't have >> to throw in error -- if one occurs, I catch it with the 'if ($@)' >> construct. Is 'catch (Exception $e)' equivalent? i.e., if an error >> occurs in a try block that isn't specifically thrown, will that >> construct catch it? >> > evals don't throw errors as far as I know, unless you throw it yourself > from within the eval. The few internal functions that do throw > exceptions can be caught using the catch(Exception $e) method, if you > want to MAKE something throw an exception, then you need to explicitly > tell it to THROW. Remember though, this is not an error-mechanism! It's > exceptions... Errors are returned the standard way, and can be handled > using error_handlers (http://www.php.net/manual/en/ref.errorfunc.php) That helps explain it a lot. Perl's eval mechanism is much more flexible, but also very non-standard from what I've been reading of C++ and Java (thanks to the person who recommended that reading). I was thinking of exceptions as a way to gracefully handle code errors, but it appears now that they are more a mechanism to handle return values that fall outside the expected realm. I'll stick to error_handlers for code errors, and start seeing what use I can make of the try{} catch(){} constructs. Off to the experimentation room... -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:[EMAIL PROTECTED] | http://vermontbotanical.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php