views:

239

answers:

2

Constructor for PHP's exception has third parameter, documentation says:

$previous: The previous exception used for the exception chaining. 

But I can't make it work. My code looks like this:

try
{
    throw new Exception('Exception 1', 1001);
}
catch (Exception $ex)
{
    throw new Exception('Exception 2', 1002, $ex);
}

I expect Exception 2 to be thrown and I expect that it will have Exception 1 attached. But all I get is:

Fatal error: Wrong parameters for Exception([string $exception [, long $code ]]) in ...

What am I doing wrong?

+6  A: 

The third parameter requires version 5.3.0.

konforce
+1  A: 

I get:

Uncaught exception 'Exception' with message 'Exception 1' ...

Next exception 'Exception' with message 'Exception 2' in ...

You using php > 5.3 ?

zaf