如何在PHP中实现异常链接

Jos*_*ábl 14 php exception chaining

PHP异常的构造函数有第三个参数,文档说:

$previous: The previous exception used for the exception chaining. 
Run Code Online (Sandbox Code Playgroud)

但我不能让它发挥作用.我的代码看起来像这样:

try
{
    throw new Exception('Exception 1', 1001);
}
catch (Exception $ex)
{
    throw new Exception('Exception 2', 1002, $ex);
}
Run Code Online (Sandbox Code Playgroud)

我希望抛出异常2,我希望它会附加异常1.但我得到的只是:

Fatal error: Wrong parameters for Exception([string $exception [, long $code ]]) in ...
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Mat*_*hew 22

第三个参数需要5.3.0版.