PHP7中的异常处理和错误处理

PHP7中异常与错误处理与之前版本对比

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、网站空间、营销软件、网站建设、五家渠网站维护、网站推广。

先上代码

ECHO PHP_VERSION.PHP_EOL;
function add (int $left,int $right){
  return $left+$right;
 }
try {
    echo add('left', 'right');
} catch (Exception $e) {
    // Handle exception
} catch (Error $e) { // Clearly a different type of object
    // Log error and end gracefully
    var_dump($e->getMessage());
}
echo PHP_EOL."helloword".PHP_EOL;

PHP v5.6.1结果

5.6.1
PHP Catchable fatal error:  Argument 1 passed to add() must be an instance of int, string given, called in C:\usertb\shareubuntu\Workerman\fortest.php on line 8 and defined in C:\usertb\shareubuntu\Workerman\fortest.php on line 3
Catchable fatal error: Argument 1 passed to add() must be an instance of int, string given, called in C:\usertb\shareubuntu\Workerman\fortest.php on line 8 and defined in C:\usertb\shareubuntu\Workerman\fortest.php on line 3
[Finished in 0.0s]

PHP v7.0.15结果

7.0.15-0ubuntu0.16.04.4
string(131) "Argument 1 passed to add() must be of the type integer, string given, called in /home/tb/win10share/Workerman/fortest.php on line 8"
helloword

区别

在于后者可以捕获fatal error,并且可以正常输出helloword

网页题目:PHP7中的异常处理和错误处理
网页网址:https://www.cdcxhl.com/article14/iijdge.html

成都网站建设公司_创新互联,为您提供网站排名网站设计手机网站建设建站公司动态网站网站策划

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网页设计公司