Languages :: PHP :: Supressing error messages |
|||
| By: Bernard |
Date: 15/11/2004 08:43:32 |
Points: 70 | Status: Answered Quality : Excellent |
| Say if I have an error on my page that a user is trying to access like a file was not included twice or a class already exists or a parse error or something, instead of showing the user a blank page or the php errors, I would like to instead save the error messages to a log file and give them a page saying that the page is currently being updated or down at the moment. Is this possible? ...And if so, how? | |||
| By: VGR | Date: 15/11/2004 08:47:30 | Type : Answer |
|
| put a "@" before the call in question, e.g. $fd = @fopen("file.txt",'r'); this won't generate any error messages. You can also switch off error reporting completly: error_reporting(0); // Turn OFF error reporting //Here comes the code that will not give errors error_reporting(2039); // Turn ON error reporting Generally, turning error reporting off is a very bad idea. If there is an error, your script will terminate for no reason at all. The best pattern to use is, if you are doing something that may result in an error, put a @ before the statement, and then check for the success of the operation and handle the error yourself. $fd=@fopen('file.txt','r'); if (!$fd) { // here treat the error case echo ("Couldn't open the file file.txt"); } else { // here access was granted // do something with the file... } Always check in the online documentation which kind of return value is sent by the function you want to use. Usually, but not always, it's a Boolean. If you fell on a function returning the infamous "a non-boolean value OR FALSE in cas of failure", then use the operator === or !== to test the returned value against FALSE. Regards |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








