Error Handling Discussion |
[eluser]Jim Higgins[/eluser]
I'm really trying to wrap my head around the process of error handling and proper user feedback for errors. Can anyone point me towards some good resources, examples, posts, or help explain the "rules" or best practice? I'm curious as to when and where I should use try/catch statements? And the proper syntax for using them? Additionally, I'm curious as to where/how to show error messages for the user when combined with the above try/catch statements? Just to preclude the standard response "See the Error Handling" class... Thank you for that response in advance. I'm looking to expand the discussion and see some more in-depth usage and handling by others. For example, when I say "where" above, I'm referring to things like: "I like to put them in my model whenever I do this... and this is how I do it. Then I throw the user a message like... and this is how I do it... etc, etc, etc" Thanks
[eluser]Jamie Rumbelow[/eluser]
There are some good built in php functions for this kind of thing. They are a bit hard to get used too, but you can get the exact line where the parse error occured - it's very powerful. See this: http://uk2.php.net/manual/en/function.se...andler.php
[eluser]mademan[/eluser]
The way I did error handling in a production CI environment was to override CI's error handler by using a post_controller_constructor hook. The main job of this custom error handler is to display a simple error message to the user and send me an email with the problem details. Here's a simplified version of the custom error handler: Code: <?php In my models I use triggers when an error occurs that my custom error handler will catch and handle: Code: <?php I used the try/catch error handler method but it seemed to over complicate and make the code base larger with no real advantage to using this type of error handling method for my purpose. I didn't need unnecessary code getting in the way. I needed something simple and unobstructive. During development I revert back to using CI default error and debugging handlers. I am curious to see how others are implementing there error handling as well. |
Welcome Guest, Not a member yet? Register Sign In |