Re: Setting try and catch to use my own error handler

From: Date: Fri, 20 Oct 2006 06:57:01 +0000
Subject: Re: Setting try and catch to use my own error handler
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-243372@lists.php.net to get a copy of this message
On Fri, 2006-10-20 at 15:50 +0900, Dave M G wrote: > 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 > You are getting confused as to what an error handler is and what a custom exception handler is. You need to define a class that extends Exception to handle your "errors" in that way. class myExceptionHandler extends Exception { ... ... public function handleError($args) { //do something } } Then when you try and instantiate your object: throw new myException("Your object is whack"); try { $obj = new Object(); } catch(myException $e) { myException::handleError(); } --Paul

« previous php.general (#243372) next »