note 99702 modified in language.exceptions by danbrown
| From: | danbrown@php.net | Date: | Tue, 31 Aug 2010 17:22:38 +0000 |
| Subject: | note 99702 modified in language.exceptions by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172208@lists.php.net to get a copy of this message | ||
Watch your namespace if you have created your own exception class.
For example:
Error.php
<?php
namespace Global;
class Error extends Exception {}
?>
Foo.php
<?php
namespace Foo;
try {
$this->foo();
} catch (Error $e) {
echo $e->getMessage();
}
?>
You WILL NOT get an error message if Error is not in the Foo namespace. Instead the Exception will
be passed upwards.
Should be:
<?php
try {
$this->foo();
} catch (Global\Error $e) {
echo $e->getMessage();
}
?>
--was--
Watch your namespace if you have created your own exception class.
For example:
Error.php
<?php
namespace Global;
class Error extends Exception {}
Foo.php
<?php
namespace Foo;
try {
$this->foo();
} catch (Error $e) {
echo $e->getMessage();
}
You WILL NOT get an error message if Error is not in the Foo namespace. Instead the Exception will
be passed upwards.
Should be:
try {
$this->foo();
} catch (Global\Error $e) {
echo $e->getMessage();
}
http://php.net/manual/en/language.exceptions.php