atrum Posted July 2, 2012 Share Posted July 2, 2012 So it has recently occurred to me that my method of error handling is sloppy and cumbersome. What I want to do is record all of the errors that occur and allow the page to finish loading. Then display them in a designated error panel on my page. Granted that if I come across a major error I do want to stop the script but for minor errors such as incorrect credentials or some other custom error I may want to display I want to neatly display them all without stopping the script. Can anyone offer any advice? Quote Link to comment https://forums.phpfreaks.com/topic/265089-need-advice-on-a-clean-way-to-handle-custom-errors/ Share on other sites More sharing options...
PeoMachine Posted August 27, 2012 Share Posted August 27, 2012 You can try to use different types of Exception. You use a "User_Exception" if you have invalid input data or something like that, and a "Database_Exception" for great errors, like loose connection. It can be like this: try { $newUser = new User(); $newUser->setCredentials('user', 'pass'); $newUser->insert(); } catch (Database_Exception $e) { // log this error // stop the script } catch (User_Exception $e) { // Display the error } Quote Link to comment https://forums.phpfreaks.com/topic/265089-need-advice-on-a-clean-way-to-handle-custom-errors/#findComment-1372806 Share on other sites More sharing options...
Christian F. Posted August 27, 2012 Share Posted August 27, 2012 A bit old thread, but it sounds like set_error_handler () is exactly what you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/265089-need-advice-on-a-clean-way-to-handle-custom-errors/#findComment-1372816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.