note 78985 added to function.set-exception-handler

From: Date: Tue, 06 Nov 2007 06:10:35 +0000
Subject: note 78985 added to function.set-exception-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-132025@lists.php.net to get a copy of this message
Hey all, i've just started to use the exception suite instead of the normal PHP error suite. For those of you looking for an object orientated way to do this without looking down at Glen and Sean's examples (Lesson 1: ALWAYS read the logs!), here you go: <?php class NewException extends Exception { public function __construct($message, $code=NULL) { parent::__construct($message, $code); } public function __toString() { return "Code: " . $this->getCode() . "<br />Message: " . htmlentities($this->getMessage()); } public function getException() { print $this; // This will print the return from the above method __toString() } public static function getStaticException($exception) { $exception->getException(); // $exception is an instance of this class } } set_exception_handler(array("NewException", "getStaticException")); throw new NewException("Catch me!!!", 69); ?> Let me know if i'm missing something obvious as I left my glasses at home and I just came back from the Melbourne cup (If I won then I wouldn't be at work still!). ---- Server IP: 203.16.234.91 Probable Submitter: 203.36.207.23 ---- Manual Page -- http://www.php.net/manual/en/function.set-exception-handler.php Edit -- https://master.php.net/note/edit/78985 Del: integrated -- https://master.php.net/note/delete/78985/integrated Del: useless -- https://master.php.net/note/delete/78985/useless Del: bad code -- https://master.php.net/note/delete/78985/bad+code Del: spam -- https://master.php.net/note/delete/78985/spam Del: non-english -- https://master.php.net/note/delete/78985/non-english Del: in docs -- https://master.php.net/note/delete/78985/in+docs Del: other reasons-- https://master.php.net/note/delete/78985 Reject -- https://master.php.net/note/reject/78985 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132025) next »