Re: error handling and __LINE__

From: Date: Tue, 20 Nov 2001 16:55:09 +0000
Subject: Re: error handling and __LINE__
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-75796@lists.php.net to get a copy of this message
| Thanks, assert() is cool, but it still reports the filename and line | number of the included file with the function in which the error | occurred, not the script that called the functon with illegal arguments. | Or...??? I see, you need a debugger :) I wrote an errorhandler class with error trapping capability. It works as follows: --index.php <?php $error = new ErrorHandler; include_once('functions.php'); $error->set_error_trap(E_ALL); // switch error trapping _on_ ! foo(123); // illegal parameter to be passed if ( $error->is_trapped(E_WARNING) ) { $this->set_error_trap(); // switch error trapping _off_ !! // following errors will be handled normally trigger_error('The place where foo() fails.', E_USER_ERROR); } ?> if you run this script, then though foo() raises a warning which won't be displayed but stored in $error (error handling object) and later you can "search" in the trap ( with is_trapped() ) to determine whether a particular error occured while the trap was switched on. Does it satisfy you or not? If yes, please mail me directly. | | Eg.: | index.php: | <? | include_once("functions.php"); | // foo() is declared here | foo(123); | // illegal argument | ?> | | This will produce a message saying an error occurred in functions.php, | but I want it to tell me that the error occurred in index.php, line 3. | Because if I call foo() many times in a script, it is difficult to find | out which call that failed. | | Is this impossible? | | Papp Gyozo wrote: | | > try, assert() instead of echo()ing error messages. | > | > assert('is_object($obj)'); | > | > and write your error handler code or use mine :) | > or am i missing something? | > | > Papp Gyozo | > - pgerzson@freestart.hu | > | > ----- Original Message ----- | > From: "SafeV" <nedenom@hotmail.com> | > To: <php-general@lists.php.net> | > Sent: Thursday, November 22, 2001 4:15 PM | > Subject: [PHP] error handling and __LINE__ | > | > | > | Hi, | > | I wonder if there's a way to find the line number of the calling script | > | from a function, like the error messages PHP generates. An example: | > | | > | In an included file I have a function and want to do something similar to: | > | | > | function foo($obj) { | > | if (!is_object($obj)) { | > | echo "Error: supplied argument is not an object in "; | > | echo __FILE__ . " line " . __LINE__; | > | } | > | ... | > | } | > | | > | But __FILE__ and __LINE__ refers to the current file, ie. the file with | > | the function in, and not the file where the function is called from. | > | The first one I can solve by using $SCRIPT_NAME, but what about the line | > | number??? | > | | > | | > | | > | -- | > | 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 |

« previous php.general (#75796) next »