Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
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


Report this thread to moderator Post Follow-up to this message
Old Post
Pugi!
08-20-07 01:04 PM


Re: How to catch a warning ?
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)

Report this thread to moderator Post Follow-up to this message
Old Post
Kim André Akerĝ
08-20-07 01:04 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:44 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.