
PHP 异常处理 总出现致命错误 无法捕获异常
<?php//创建可抛出一个异常的函数functioncheckNum($number){if($number>1){thrownewException("Valuemu...
<?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
请问这是什么原因呢 用其他的测试也同样是 致命错误啊
我的是PHP5啊 我反射API 可以看到Exception类啊 你的 正常显示吗?
我做了一个试验 证明了我的PHP中 代码里面有无catch出现的结果都是一样的 也就是说catch没有作用 这该如何解决 展开
//创建可抛出一个异常的函数
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
请问这是什么原因呢 用其他的测试也同样是 致命错误啊
我的是PHP5啊 我反射API 可以看到Exception类啊 你的 正常显示吗?
我做了一个试验 证明了我的PHP中 代码里面有无catch出现的结果都是一样的 也就是说catch没有作用 这该如何解决 展开
2个回答
展开全部
没有错啊?
上一个可以显示,下一个你可能重写了Exception,也应该没错。
难道你的PHP不支持异常?
Uncaught exception 'Exception' ,有这个,没道理啊?
上一个可以显示,下一个你可能重写了Exception,也应该没错。
难道你的PHP不支持异常?
Uncaught exception 'Exception' ,有这个,没道理啊?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询