#30379 [Opn->Bgs]: Example of Exception $e is Incorrect
| From: | aidan@php.net | Date: | Sun, 10 Oct 2004 07:40:42 +0000 |
| Subject: | #30379 [Opn->Bgs]: Example of Exception $e is Incorrect | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969364473@lists.php.net to get a copy of this message | ||
ID: 30379
Updated by: aidan@php.net
Reported By: hans at nyphp dot com
-Status: Open
+Status: Bogus
Bug Type: Documentation problem
Operating System: Irrelevant
PHP Version: Irrelevant
New Comment:
echo $e will call the exception classes __toString method. This will
show more information than just getMessage(). This isn't a mistake.
However, the docs are not very good - I'll have a look at them today.
Previous Comments:
------------------------------------------------------------------------
[2004-10-10 06:33:43] hans at nyphp dot com
Description:
------------
On the page that gives examples of how to use Exceptions:
http://www.php.net/manual/en/language.oop5.exceptions.php
The usage of catch() is incorrect in the examples. This code:
catch (Exception $e) {
echo "Caught exception: ", $e, "\n";
}
Would echo something like:
Caught exception: Object id #3
I cannot believe this is the desired output. This code:
catch (Exception $e) {
echo "Caught exception: ", $e->getMessage(), "\n";
}
Would provide the expected output:
Caught exception: Always throw this error
In other words, all exception code examples with echo statements of $e
should contain $e->getMessage() rather than just echoing $e.
Hans
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30379&edit=1