PHP 异常处理 总出现致命错误 无法捕获异常

来源:百度知道 编辑:UC知道 时间:2024/07/05 16:11:18
<?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();
}
?>
上面代码将获得类似这样一个错误:

Message: Value must be 1 or below

但浏览器出现的是
Fatal error: Uncaught exception 'Exception' with message 'Value must be 1 or below' in D:\webserver\wwwroot\sturn\html\cs.php:7 Stack trace: #0 D:\webserver\wwwroot\sturn\html\cs.php(15): checkNum(2) #1 {main} thrown in D:\webserver\wwwroot\sturn\html\cs.php on line 7

请问这是什么原因呢 用其

没有错啊?
上一个可以显示,下一个你可能重写了Exception,也应该没错。
难道你的PHP不支持异常?
Uncaught exception 'Exception' ,有这个,没道理啊?

看看再说