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". Link to comment https://forums.phpfreaks.com/topic/281039-how-to-handle-errors/ 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. Link to comment https://forums.phpfreaks.com/topic/281039-how-to-handle-errors/#findComment-1444383 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. Link to comment https://forums.phpfreaks.com/topic/281039-how-to-handle-errors/#findComment-1444432 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.