how catch a warning by file_put_contents() ?
| From: | Andreas | Date: | Sat, 20 Aug 2011 04:51:17 +0000 |
| Subject: | how catch a warning by file_put_contents() ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-314576@lists.php.net to get a copy of this message | ||
Hi,
I wrote stuff with file_put_contents() in a try{} catch{} and it worked.
Then I'd like to check what happens when some error occurs so I writeprotected the targetfile.
Instead of getting my own message by the catch{} block I got a standard warning in the browser.
Can't I catch those warnings, too?
And why does this function rise a warning when it can't acomplish it's task?
Samplecode:
try {
$msg = date ("d.m.Y H:i:s") . 'This should be stored in the file.';
file_put_contents( '/tmp/exceptions.txt', $msg . "\n", FILE_APPEND);
}
catch ( Exception $e ) {
$msg = "Exception " . $e->getCode() . " / " . $e->getMessage();
echo "<p>$msg</p>";
}