Error::getPrevious
(没有可用的版本信息,可能只在 Git 中)
Error:: getPrevious - 返回以前的 Throwable
描述
final public Throwable Error::getPrevious ( void )
返回前一个 Throwable(Error :: __ construct()的第三个参数)。
参数
该功能没有参数。
返回值
返回前面的 Throwable(如果可用或NULL
否则)。
例子
示例#1 Error :: getPrevious()示例
循环并打印出错误跟踪。
<?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());
}
?>
上面的例子会输出类似于:
/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 →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com