0
点赞
收藏
分享

微信扫一扫

PHP7版本以上请用Throwable 捕捉异常和错误

Aliven888 2022-01-27 阅读 55
php

之前一直用exception 捕捉异常

后来发现一次异常捕捉不到了(其实是错误)

7以上exception与error是分开的

Throwable does not work on PHP 5.x.

To catch both exceptions and errors in PHP 5.x and 7, add a catch block for Exception AFTER catching Throwable first.
Once PHP 5.x support is no longer needed, the block catching Exception can be removed.

try
{
   // Code that may throw an Exception or Error.
}
catch (Throwable $t)
{
   // Executed only in PHP 7, will not match in PHP 5
}
catch (Exception $e)
{
   // Executed only in PHP 5, will not be reached in PHP 7
}
举报

相关推荐

0 条评论