Home  >  Article  >  Backend Development  >  PHP exception catching code

PHP exception catching code

不言
不言Original
2018-04-26 17:11:561280browse

This article mainly introduces the code for catching exceptions in PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

//创建可抛出一个异常的函数
function checkCash($number){
 	if($number != 1){
  		throw new Exception("状态不等于1抛出异常");
  	}
 	return true;
}

//在 "try" 代码块中触发异常
try{
	//使用0去触发异常
 	checkCash($ret_arr['status']);
}

//捕获异常
catch(Exception $e)
{
 	newDie('异常捕获');
}

Related recommendations:

[php manual]Exception handling

PHP 7 error exception level



The above is the detailed content of PHP exception catching code. For more information, please follow other related articles on the PHP Chinese website!

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