Home > Archive > PHP Language > August 2007 > How to catch a warning ?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to catch a warning ?
|
|
|
| I use the function error_log for logging like this
if (!error_log($logmsg, 3, $dest)) {
throw new Exception('Failed to write to log');
}
and this inside an try catch block. In the catch I send an email.
For testing purposes I disabled write for apache user on the
destination directory.
I got the following message
Warning: error_log(path and logfile) [function.error-log]: failed to
open stream: Permission denied ...
Why do I get this message. I test for it, it is inside a try catch
block ...
It is still in development. On a production server I can do
error_reporting(E_ERROR) or in php.ini set display_errors=off. But why
a warning: I take care of it. Or is this normal ?
JM
| |
| Kim André Akerĝ 2007-08-20, 8:04 am |
| Pugi! wrote:
> I use the function error_log for logging like this
> if (!error_log($logmsg, 3, $dest)) {
> throw new Exception('Failed to write to log');
> }
>
> and this inside an try catch block. In the catch I send an email.
> For testing purposes I disabled write for apache user on the
> destination directory.
> I got the following message
> Warning: error_log(path and logfile) [function.error-log]: failed to
> open stream: Permission denied ...
> Why do I get this message. I test for it, it is inside a try catch
> block ...
>
> It is still in development. On a production server I can do
> error_reporting(E_ERROR) or in php.ini set display_errors=off. But why
> a warning: I take care of it. Or is this normal ?
>
> JM
In PHP 5.0 or later, you can define the E_WARNING error type to be
handled by your own functions, like this:
set_error_handler("my_warning_handler", E_WARNING);
function my_warning_handler($errno, $errstr) {
// do something
}
http://php.net/set_error_handler
In PHP 4.x, you can do it the same way, but instead filter out the
E_WARNING to your own, and pass the others out to the normal error
handler (as the manual says, "[if] the function returns FALSE then the
normal error handler continues"), like this:
set_error_handler("my_warning_handler");
function my_warning_handler($errno, $errstr) {
switch ($errno) {
case E_WARNING:
// do something
return true;
break;
default:
return false;
break;
}
}
--
Kim André Akerĝ
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
|
|
|
|
|