Re: Exception not being caught
| From: | David Otton | Date: | Thu, 16 Jul 2009 11:42:18 +0000 |
| Subject: | Re: Exception not being caught | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-295456@lists.php.net to get a copy of this message | ||
2009/7/15 Weston C <westonc@gmail.com>:
> <?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.