Home  >  Article  >  Backend Development  >  php错误处理

php错误处理

WBOY
WBOYOriginal
2016-06-13 13:19:49888browse

php异常处理

function onError($errCode, $errMesg, $errFile, $errLine) {        
		echo "Error Occurred\n";        
		throw new Exception($errMesg);    
	}     
	function onException($e) {        
		echo $e->getMessage();    
	}     
	set_error_handler("onError");     
	set_exception_handler("onException"); 
	try {
		$mm=0/0;
		echo $mm;
	} catch (Exception $e) {
		echo $e->getCode()."\n";
		echo $e->getMessage()."\n";
	}


--------------------------------
一定要定义和调用
set_error_handler("onError");    
set_exception_handler("onException");
否则  进不去catch(){}里面去的
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn