首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Error::getPrevious

(没有可用的版本信息,可能只在 Git 中)

Error:: getPrevious - 返回以前的 Throwable

描述

代码语言:javascript
复制
final public Throwable Error::getPrevious ( void )

返回前一个 Throwable(Error :: __ construct()的第三个参数)。

参数

该功能没有参数。

返回值

返回前面的 Throwable(如果可用或NULL否则)。

例子

示例#1 Error :: getPrevious()示例

循环并打印出错误跟踪。

代码语言:javascript
复制
<?php
class?MyCustomError?extends?Error?{}

function?doStuff()?{
????try?{
????????throw?new?InvalidArgumentError("You?are?doing?it?wrong!",?112);
????}?catch(Error?$e)?{
????????throw?new?MyCustomError("Something?happened",?911,?$e);
????}
}


try?{
????doStuff();
}?catch(Error?$e)?{
????do?{
????????printf("%s:%d?%s?(%d)?[%s]\n",?$e->getFile(),?$e->getLine(),?$e->getMessage(),?$e->getCode(),?get_class($e));
????}?while($e?=?$e->getPrevious());
}
?>

上面的例子会输出类似于:

代码语言:javascript
复制
/home/bjori/ex.php:8 Something happened (911) [MyCustomError]
/home/bjori/ex.php:6 You are doing it wrong! (112) [InvalidArgumentError]
  • Throwable :: getPrevious() - 返回以前的 Throwable

← Error::getMessage

Error::getCode →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com