Jump to content

Recommended Posts

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

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.

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.