Catch Fatal Errors |
[eluser]dmorin[/eluser]
I'm curious if anyone has implemented something where fatal errors can be caught by codeigniter and have a nice page returned to the user instead of a blank page when display_errors is turned off. There are many situations where a fatal error might be thrown on a production site. The most likely example for me is if the database is unreachable.
[eluser]Chris Newton[/eluser]
I do have something like this set up. It's a library I made called error_sender, and basically it allows me to co-opt the standard error display to suit my own purposes. It requires that display_errors be turned on though. The message shown to the user is my message however, rather than the standard PHP message, and I've changed the standard template to use something a little more visually pleasing. Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); This doesn't catch fatal errors (most of which can't be caught) but at least let's me account for some pretty catastrophic errors that might occur, like the DB being unreachable, with error messaging provided to the user on what they should do.
[eluser]dmorin[/eluser]
Thanks for replying with your error code. I did find a way to catch fatal errors. Basically, you have to modify your index.php script and change Code: require_once BASEPATH.'codeigniter/CodeIgniter'.EXT; Code: ob_start(); The code is from http://www.eggplant.ws/blog/php/mayday-php-going-down/. The idea is instead of printing out the Bad Stuff Happened and errors, I could return a decent looking page back to the browser that says "An unrecoverable error has occurred. Please use the back button to return to the previous page". It's certainly difficult though since we have no way of knowing what CI helpers/libraries are loaded and therefore need to do everything without them in a way that's virtually certain to never throw an error. If anyone has comments on how to better implement this, or if you see an issue with the code above, let me know. I wasn't sure if adding in another lever of ob_buffers would mess with loading views, but it seems to work correctly. |
Welcome Guest, Not a member yet? Register Sign In |