php 开启报错

// 开启报错提醒
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);

// 某一段代码查找异常

<?php
//创建可抛出一个异常的函数
function checkNum($number)
 {
 if($number>1)
  {
  throw new Exception("Value must be 1 or below");
  }
 return true;
 }

//在 "try" 代码块中触发异常
try
 {
 checkNum(2);
 //If the exception is thrown, this text will not be shown
 echo 'If you see this, the number is 1 or below';
 }

//捕获异常
catch(Exception $e)
 {
 echo 'Message: ' .$e->getMessage();
 }
?>

猜你喜欢

转载自www.cnblogs.com/init-007/p/11003036.html