You are here: Re: How to catch a warning ? « All PHP « IT news, forums, messages
Re: How to catch a warning ?

Posted by Kim Andrι Akerψ on 08/20/07 11:19

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)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация