我认为在所有编程语言中Exception
类都是Throwable
接口的实例.
看一下下面的代码,它显示Exception
的不是Throwable
php中的实例.
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
}
}
Run Code Online (Sandbox Code Playgroud)
它会产生链接异常的问题,其中Exception
类构造函数接受Throwable
它的最后一个参数.
php版本: 5.6.23
有解决方案吗