|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-10-10 06:33 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 14:00:01 2025 UTC |
While the _toString() should be called, in PHP 5.0.2 echoing an object, $e of class Exception, doesn't always call the _toString() method. So perhaps this is more than a documentation problem. For example, given this catch{} block: catch( Exception $e ) { $ref = new ReflectionObject($e); echo var_export($ref->getMethods(),1); echo "My Error: ".$e; } This outputs (shortended form): array ( ... 8 => class ReflectionMethod { public $name = '__toString'; public $class = 'Exception'; }, ) My Error: Object id #3 H