Setting try and catch to use my own error handler
| From: | Dave M G | Date: | Fri, 20 Oct 2006 06:50:32 +0000 |
| Subject: | Setting try and catch to use my own error handler | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-243371@lists.php.net to get a copy of this message | ||
PHP List,
I have a system where the code parses the URL and creates objects based on the classes named in the link.
In order to prevent a user typing in a URL that contains an object that doesn't exist, and getting an error, I'm trying to set up an error handler class, called ErrorHandler, that will handle it.
I set the error handler to be my own, and then put a Try and Catch around the part of the code that
set_error_handler(ErrorHandler::handleError());
try
{
object = new $urlParts[0]();
if (!empty($urlParts[2]))
{
$object->$urlParts[1]($urlParts[2]);
}
else
{
$object->$urlParts[1]();
}
}
catch (Error $e)
{
echo "Sorry, the web page you are looking for can not be found.";
}
Inside my ErrorHandler, I have this:
public static function handleError($errno, $errstr, $errfile, $errline)
{
echo "Hey dude! Error! " . $errno . $errstr . $errfile . $errline ;
}
However, I get errors saying that the arguments for handleError don't exist.
Shouldn't they be automatically passed to my own error handler?
Thank you for any advise.
--
Dave M G
Ubuntu 6.06 LTS
Kernel 2.6.17.7
Pentium D Dual Core Processor
PHP 5, MySQL 5, Apache 2