kid_drew Posted April 5, 2007 Share Posted April 5, 2007 Hey guys, So, if I have a PHP error that would normally dump to the screen, can I catch that error and instead divert the user to an error page that would say something like "We have encountered a server error. Blah blah blah." I'd really rather the user didn't see "Database connection failed" or "Call to member function on non-object". -Drew Link to comment https://forums.phpfreaks.com/topic/45743-catching-php-errors/ Share on other sites More sharing options...
pocobueno1388 Posted April 5, 2007 Share Posted April 5, 2007 At the end of your query put: or die("We have encountered a server error. Blah blah blah."); Here is an example of it used with a query: mysql_query("UPDATE table SET col='$blah'")or die("We have encountered a server error. Blah blah blah."); Link to comment https://forums.phpfreaks.com/topic/45743-catching-php-errors/#findComment-222209 Share on other sites More sharing options...
utexas_pjm Posted April 5, 2007 Share Posted April 5, 2007 You can override PHP's error reporting: http://us3.php.net/set_error_handler Best, Patrick Link to comment https://forums.phpfreaks.com/topic/45743-catching-php-errors/#findComment-222238 Share on other sites More sharing options...
per1os Posted April 5, 2007 Share Posted April 5, 2007 The only way to really catch an error like ASP etc provides is to have PHP 5 as it has the TRY/Catch implementation. Link to comment https://forums.phpfreaks.com/topic/45743-catching-php-errors/#findComment-222274 Share on other sites More sharing options...
kid_drew Posted April 5, 2007 Author Share Posted April 5, 2007 What I want is if the user encounters an error, I want to display an error page instead of the intended page, and I want that error page to still have the page layout of the rest of my pages. If you create your own error handler function, can you call your formatting scripts from inside the function so that the page that displays instead still looks like it belongs to your site? I.e. function custom_error_handler($errno, $errstr, $errfile, $errline, $errcontext){ require "header.php"; // Insert error code here require "footer.php"; } Or should I actually redirect them to an error page? Maybe the try/catch method is best for what I'm trying to do. You can override PHP's error reporting: http://us3.php.net/set_error_handler Best, Patrick Link to comment https://forums.phpfreaks.com/topic/45743-catching-php-errors/#findComment-222303 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.