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-excepti
on-handler.php
Edit -- https://master
.php.net/note/edit/78985
Del: integrated -- h
ttps://master.php.net/note/delete/78985/integrated
Del: useless -- http
s://master.php.net/note/delete/78985/useless
Del: bad code -- htt
ps://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 -- http
s://master.php.net/note/delete/78985/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78985
Reject -- https://mast
er.php.net/note/reject/78985
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|