PHP 8.5.0 Alpha 2 available for testing

Voting

: eight minus two?
(Example: nine)

The Note You're Voting On

frank at netventures dot com dot au
17 years ago
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!).

<< Back to user notes page

To Top