Page 1 of 1

error reporting problem[solved]

Posted: Fri Feb 23, 2007 5:28 am
by raghavan20
I have an error handler, i do not receive fatal error calls to this function. Here, I intentionally mispell an object and try to call a method that belongs to the object. i get the notice error in handler but not the fatal error. Any ideas?

received error on screen

Code: Select all

my error handler called
; errno: 8; errstr: Undefined variable: TemplateManager
current run type: production
Fatal error: Call to a member function getUnit() on a non-object in /home/thisisra/public_html/home/controllers/PW_C_AboutMe.php on line 45
the error handler

Code: Select all

//define error handler
function myErrorHandler($errno, $errstr, $errfile, $errline){
	
	echo "<h4>my error handler called</h4>; errno: $errno; errstr: $errstr";
	echo "<br />current run type: " . CurrentRunType;
	$msg = "
	<div style = 'text-align:center;'>
		<h3>www.thisisraghavan.com</h3>
		I am aware of this error and I will fix this soon. 
		I appreciate your co-operation
	</div>";
	
	switch ( TRUE ) {
	 	case ( $errno == E_USER_ERROR || $errno == 1 ):{
			if( CurrentRunType == 'test' ){
				
				echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
				echo "  Fatal error on line $errline in file $errfile";
				echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
				echo "Aborting...<br />\n";
				
			}else{
				echo $msg;
			}
			exit(1);
			break;
		}
		
		case ( $errno == E_USER_WARNING || $errno == 2 ):{
			if( CurrentRunType == 'test' ){
				echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
			}
			break;
		}
		
		case ( $errno == E_USER_NOTICE || $errno == 8 ):{
			if( CurrentRunType == 'test' ){
				echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
			}
			break;
		}
		
		default:{
			if( CurrentRunType == 'test' ){
				echo "Unknown error type: [$errno] $errstr<br />\n";
			}
			break;
		}
	}

   /* Don't execute PHP internal error handler */
   return true;
}

Posted: Fri Feb 23, 2007 7:20 am
by Begby
This is either because your error handler was not loaded before the error occured, or more likely that this error causes an immediate exit with no further code execution, so its not possible to catch.

Posted: Fri Feb 23, 2007 9:46 am
by volka
raghavan20 wrote:Fatal error: Call to a member function getUnit() on a non-object in
http://de2.php.net/set_error_handler wrote:The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
"Fatal error" means E_ERROR.

Posted: Fri Feb 23, 2007 10:34 am
by raghavan20
volka wrote:
raghavan20 wrote:Fatal error: Call to a member function getUnit() on a non-object in
http://de2.php.net/set_error_handler wrote:The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
"Fatal error" means E_ERROR.
that explains a lot. but if you cannot handle E_ERROR, then this is not going to be of much use as we cannot perform any error related operations or mailing, so the only chance of debugging would be looking at the error log.

Posted: Fri Feb 23, 2007 11:38 am
by Begby
If you are using PHP 5 you should look into using exceptions, it might help you out. As for fatal errors, these are typically things that happen in development, not usually things that crop up later while the app is under use (assuming that your app is well written). Fatal errors are things like compile errors and other blatant things such as missing semicolons or in your case trying to access a method on something that isn't an object.