RE: [PHP] Simple error handling... but how? - Register your own error-handler with PHP
| From: | Neil Kimber | Date: | Tue, 09 Jan 2001 17:46:17 +0000 |
| Subject: | RE: [PHP] Simple error handling... but how? - Register your own error-handler with PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33503@lists.php.net to get a copy of this message | ||
Ques. 1
I've also experienced the same thing. However, I'm not too concerned about
it as I normally try to write code that produces no warnings (better safe
than sorry). This is new functionality, so it's possible that it hasn't been
implemented very strongly. Since using an error handler I've picked up lots
(and I mean lots) of code problems, ranging from actual code errors through
to redefinitions or no declaration warnings. I just go through and fix each
one as I find them. It only takes a second and forces good coding practices.
As for returning control to the program, this happens anyway. If the error
isn't fatal then you'll get a message logged and then control will simply
return. Maybe you mean that you want your error handler to ignore certain
errors. Not too sure of the best approach. It would be nice if the
error_reporting() method worked correctly.
Ques. 2
I found this functionality mentioned in the change dox for 4.02. I was
already using asserts throughout my code and had been waiting for similar
functionality regarding error handling. You can see the release notes here:
http://www.php.net/ChangeLog-4.php
search for 'error handler'
There are some other handlers that are available - but they're of little use
to me and I don't use them.
Regards,
Neil
-----Original Message-----
From: Diego Fulgueira [mailto:dful@metahogar.com]
Sent: 09 January 2001 17:32
To: Php-General; Neil Kimber
Subject: RE: [PHP] Simple error handling... but how? - Register your own
error-handler with PHP
Thanks Neil! It's working fine.
I got two questions now, I hope you have time to aswer them. The first one
might be too much to ask for, so don't mind to give me a short answer like
"You can't do that":
1. I don't want to handle warnings, only errors o even just fatal errors. I
tried setting error_reporting(), but this has no efect: all errors,
including warnings, are handled. Therefore, I need a way to know what type
of error has occurred. And, if i don't want to handle that error, how can I
return program control to line where the error happened?.
2. Where did you learned that? I want to know if there are other types of
handlers that I can register.
Thanks a lot.
-----Original Message-----
From: Neil Kimber [mailto:neil.kimber@flytxt.com]
Sent: Tuesday, 09 January, 2001 3:56 AM
To: Diego Fulgueira; Php-General
Subject: RE: [PHP] Simple error handling... but how? - Register your own
error-handler with PHP
You can register your own error-handler using the function:
set_error_handler(<error_handler_function_name>);
Your customised error_handler will then get called whenever an error gets
called. Your function is passed the follwing parameters:
function error_handler_function_name($errno, $errstr, $errfile, $errline)
This is nice as it passes you the file and line number as well as the error
number and the error string. You can then use this for sending your own
informational debug messages to the error handler by using the
trigger_error() routine.
The handler that I use dumps everything to a debug file - using error_log().
This is great as I get all of my parsing errors and informational debug
messages sent to the same place. By sending them to a file (rather than the
screen) you stop headers being sent, which in turn could cause you problems.
I believe that this functionality only became available in 4.02.
You may also want to check out the assert() functions. These are similar and
are great for putting sanity checks into your code. I think that the assert
handler code was the inspiration for the error handling code.
Hope this helps,
Neil
-----Original Message-----
From: Diego Fulgueira [mailto:dful@metahogar.com]
Sent: 08 January 2001 22:00
To: Php-General
Subject: [PHP] Simple error handling... but how?
Ok. This might have been widely discussed already, but I haven't been able
to find useful information about it:
How can I present a customized error page whenever a PHP error or warning
ocurrs?
Thanks in advance.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net