Error Handling in PHP – Display Custom Message

by Kishore on March 24, 2009

PHP Error Handling I was working on the Kish Twitter plugin  which is a Wordpress Twitter Plugin was getting some errors when the Twitter API was  down or there were some issues when parsing the Search RSS feeds. I thought of displaying a custom Error message rather than the PHP error. Its always good to use custom error handling so that the web page does not break up or create a bad impression on your visitor.

We create a custom error handling function which is called when ever an error is triggered and displays the custom error message.

This function must be able to handle a minimum of two parameters (error level and error message) but can accept up to five parameters (optionally: file, line-number, and the error context):

function kish_Error_handler($errno, $errstr)  { 
    echo "<b>Error:</b> [$errno] $errstr<br />";
    echo "There was an error while processing your request";
}
// call this inside the function to handle the error
 
set_error_handler("kish_Error_handler");

You can find more about PHP Error Handling here.

Possibly Interesting Posts

New Guidelines for Plugin Developers - Wordpress : Mark Jaquith has written on his blog on the Wordpress plugin repository where Plugin Authors can hos..[](0)
Adobe Plugs 13 Security Holes in Critical Update : Adobe Systems embarks on a new schedule for security updates with 13 critical fixes in tow for Reade..[](1)
Security Expert Suggests Twitter Focus on Output Escaping not Input Filtering : Twitter's status blog this morning announced that Twitter has addressed the most recent variant of..[](1)
Checklist for submitting your plugin to Wordpress Extension Directory : You will be knowing that Wordpress can host your plugin at the Wordpress Extension Directory. You c..[](57)

Leave a Comment

Previous post:

Next post: