【发布时间】:2017-05-02 16:30:30
【问题描述】:
我认为在所有编程语言中Exception 类都是Throwable 接口的实例。
看看下面的代码,它显示Exception 不是 php 中Throwable 的实例。
try {
throw new InvalidArgumentException("error message");
} catch (InvalidArgumentException $e) {
if ($e instanceof Exception) {
echo '$e is exception'; // this line gets executed
}
if ($e instanceof Throwable) {
echo '$e is throwable'; // but this one never
}
}
在 Exception 类构造函数的最后一个参数中接受 Throwable 时,链式异常会出现问题。
php版本:5.6.23
有什么办法吗?
【问题讨论】:
-
是的 - eval.in/785678