* 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>
> class foo {
>   function myException() {
>     throw new MyException('Exception thrown');
>   }
>   function standardException() {
>     throw new Exception();
>   }
> }
>
> $f = new foo();
>
> try {
>   $f->myException();
> }
> catch (MyException $e) {
>   echo "Caught my exception\n", $e;
>   $e->customFunction();
> }
> catch (Exception $e) {
>   echo "Default Exception caught\n", $e;
> }
>
> try {
>   $f->standardException();
> }
> catch (MyException $e) {
>   echo "Caught my exception\n", $e;
>   $e->customFunction();
> }
> catch (Exception $e) {
>   echo "Default Exception caught\n", $e;
> }

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?

-- 
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

Reply via email to