JamesConnor Posted August 11, 2013 Share Posted August 11, 2013 Whilst developing my website I use mysql_error() to display errors so I know how to fix them. My question is... when the website goes live, how should I handle the errors, because I do not want the user to see the errors but instead see a user friendly message like "Oops, something went wrong". Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 11, 2013 Share Posted August 11, 2013 one way is to use trigger_error() to handle your mysql_error output. trigger_error uses the php error handling settings. you can set display_errors ON for development to send the messages to the browser, and set display_errors OFF and log_errors ON to send them to the error log file on the live server. you would add code for your user 'Oops ...' error message to always be output. Quote Link to comment Share on other sites More sharing options...
kicken Posted August 11, 2013 Share Posted August 11, 2013 I handle them by throwing an exception which is then caught at the top level and results in a generic error page being displayed. Eg, I have a router page something like: try { include($thePage); } catch (Exception $e){ ShowErrorPage($e); } The ShowErrorPage function just loads up a error template file displays it. I have a constant set in the app config file to determine whether error details are displayed. If it is true then the exception details and stack trace are displayed on the page, if false they are not. In either case, the error details are also logged to a file. Quote Link to comment 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.