RE: [PHP] when using die(), how can i get the line number that errored?

From: Date: Tue, 30 Jan 2001 10:52:01 +0000
Subject: RE: [PHP] when using die(), how can i get the line number that errored?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37282@lists.php.net to get a copy of this message
Rather than use die() why not use trigger_error() and have an error_handler registered with the parser. Firstly, create an error handler and register it - I use something like the following: function myErrorHandler($errno, $errstr, $errfile, $errline) { $locStrMessage = $errfile . " " . $errline . " " . $errno . " : " . $errstr; error_log($locStrMessage . "\r\n",3,'debug/debug.log'); } Register this in your autoprepend file using: set_error_handler("myErrorHandler"); Now, whenever you get an error it gets logged to your debug file with the file and line number. You can 'generate' errors using trigger_error() and pass it a string of information. You can use this method to catch absolute bad bugs and also to dump useful debug information. This is quiet an elementary implementation of good error handling, you can take this and extend it into quite a useful system for tracking bugs. You could add system flags for turning debug on and off, alter levels of debugging etc... regards, Neil p.s. assert() is cool too. -----Original Message----- From: Richard Lynch [mailto:richard@zend.com] Sent: 30 January 2001 08:50 To: php-general@lists.php.net Subject: Re: [PHP] when using die(), how can i get the line number that errored? function errtrapper($file, $line){ echo "In $file on line $line<BR>\n"; #current body here. } die(errtrapper(__FILE__, __LINE__)); -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: "Noah Spitzer-Williams" <noahsw@cyberdude.com> Newsgroups: php.general Sent: Monday, January 29, 2001 6:59 PM Subject: [PHP] when using die(), how can i get the line number that errored? > here's my code: > > $res = mysql_query($badsqlstatement) or die(errtrapper()); > > inside errtrapper(), is there a way to find out what line this error > occurred? > > thanks!! > > - Noah > > > > -- > 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 (#37282) next »