Home > Backend Development > PHP Tutorial > php错误处理

php错误处理

WBOY
Release: 2016-06-13 13:19:49
Original
941 people have browsed it

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";
	}
Copy after login


--------------------------------
一定要定义和调用
set_error_handler("onError");    
set_exception_handler("onException");
否则  进不去catch(){}里面去的
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template