iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-09-2007, 02:36 PM
WebProWorld New Member
 
Join Date: Dec 2007
Posts: 3
tony.willson RepRank 0
Default Error handling

We struggle to come up with a decent error handling function. I thought that I use a global variable $live to easily make a switch from testing to live. I will keep the function in an include file.
I kind of got there to print a "user-friendly" message when the site is live, but it messes up the whole page layout. Don't how to print the error message in the content area. How would I adjust my error handler and what would I add to "<?php require_once $content; ?>"?
My error handler:
<?php
/*-- start output buffering--*/
ob_start();
/*-- live site --*/
$live=TRUE;
/*-- error handling function giving back error number, the actual message, the error file, the error line and the variables (what are variable in this context?) --*/
function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) {
/*-- make $live global --*/
global $live;
/*-- set error message for testing together --*/
$message="Error in file '$e_file' on line $e_line: $e_message\n";
$message.=print_r($e_vars,1);
/*-- error message for live site should not give any detail about problem, just an apology --*/
if($live){
$user="We apologise for the problems on this page...";
/*-- if there are error messages print the standard user message --*/
if ($message==0){echo $user;}else{
/*-- otherwise say 'hi there' --*/
echo ('');}
/*-- do it only once as user should not see the apology more than once --*/
exit();
} else {
/*-- if site is in testing print the acual error messages --*/
echo '<div class="error">'.$message.'</div><br/>';
}
}
ob_end_flush();
/*-- as everything is defined now, set the error handler, so it's ready to be used --*/
set_error_handler('my_error_handler');
?>
Also, in the bit "if ($message==0)" I would have thought that comparing $message to 1 would have printed the user-friendly error message (as I thought 1 means that there is one or more error message).

Any help appreciated.
Reply With Quote
  #2 (permalink)  
Old 12-10-2007, 06:25 AM
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Cornwall, UK
Posts: 972
speed RepRank 1
Default Re: Error handling

See the thread error handler as your PHP is wrong.

As for printing in the content area, the error message will always be output at the point it occurs, unless you capture the page template along with any good data and the error(s). You then need to combine and output the result. It's much easier to just output an error page.

After all should an application really continue after an error has occurred? What about knock on effects from the 1st error?
Reply With Quote
  #3 (permalink)  
Old 01-02-2008, 06:53 PM
WebProWorld New Member
 
Join Date: Jan 2008
Posts: 3
aaron_s RepRank 0
Default Re: Error handling

I should go ahead and also make two suggestions:

1) Develop a custom exception handler as well.
2) Your LIVE conundrum - why don't you make it based off of the URL or something like that? That is, unless you rewrite the local IP of your testing server to be the exact same as the live... I tend to do it based off of $_SERVER['HOST_NAME'] to determine my environment.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Questionnaire data handling perpetuum-mobile Web Programming Discussion Forum 1 02-28-2007 07:28 PM
Handling 404's astoller Google Discussion Forum 2 03-21-2006 12:44 AM
Runtime Error - Line 1 - Error Syntex Error charms987 Graphics & Design Discussion Forum 6 07-29-2005 12:56 PM
Handling events with the DOM - Part III WPW_Feedbot Graphics & Design Discussion Forum 0 05-07-2005 07:43 PM
Handling events with the DOM, part II WPW_Feedbot Graphics & Design Discussion Forum 0 05-02-2005 03:06 PM


All times are GMT -4. The time now is 04:25 AM.



Search Engine Optimization by vBSEO 3.3.0