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();
 }
?>

 

posted @ 2019-06-11 13:01  study_php_java_C++  阅读(4543)  评论(0编辑  收藏  举报