Re: Exception not being caught

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There are many examples of error_handlers at
http://ar.php.net/manual/es/function.set-error-handler.php

The handler only have to cast the error to exception.

YOu can write a simple handler or a fully featured one, but the essence is
the same...

function errorHandler(/*args*/)
{
    $e = new Exception( $message, $code );
    throw $e;
}

On Thu, Jul 16, 2009 at 8:42 AM, David Otton <
phpmail@xxxxxxxxxxxxxxxxxxxxxxx> wrote:

> 2009/7/15 Weston C <westonc@xxxxxxxxx>:
>
> > <?php
> >
> > class A { }
> >
> > $a = new A();                           // Ayn would be proud, right?
> >
> > try {
> >    echo "a is ",$a,"\n";
> > } catch(Exception $e) {
> >    echo "\nException Caught: ";
> >    echo $e, $n;
> > }
> >
> > ?>
> >
> > This does not run as expected. I'd think that when the implicit string
> > conversion in the try block hits, the exception would be thrown,
> > caught by the catch block, and relayed.
> >
> > Instead you don't ever see the words "exception caught" and you get
> > "Catchable fatal error: Object of class A could not be converted to
> > string."
> >
> > If it's catchable, why isn't it caught in my example?
>
> It's not an exception, it's a "fatal error". Fatal errors are caught
> by error handling functions, not by catch blocks.
>
> Consequence of having (at least) two separate error handling
> mechanisms in the same language.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Martin Scotta

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux