Handling errors in PHP 4 as you all might know has always been a pain in the ass. Along with PHP 5 has comes much better exception handling. When you want to throw an exception you can use code like the following
this code will throw an error because you cannot divide by 0, you will see how the information is printed to the screen.
Now you can also extend the Exception class for much more extendability.
Class DatabaseException extends Exception {
public function __construct($msg) {
parent::__construct($msg);
}
}
when you want to throw an error, say you have this
$query = mysql_query("SELECT * FROM table") or die(mysql_error());
this is how we would have done this before, now we can do this differently to show a nice message to the user without actually stopping everything, you can show a nice message formatted and fitted for your site design ;)
$query = mysql_query("SELECT * FROM table") or throw new DatabaseException('Database Query Failed!");
this code alone is not a complete sample however extending the exception class will allow you to create other methods that you can call to output the design before and after you call the parent::__construct() method.
I hope you guys like this new error handling, any questions use the comment system or weberdev@codebowl.com