Home > Backend Development > PHP Tutorial > PHP exception catching code

PHP exception catching code

不言
Release: 2023-03-24 22:08:01
Original
1313 people have browsed it

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('异常捕获');
}
Copy after login

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!

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