php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66425 Misleading fatal error with nested exceptions
Submitted: 2014-01-06 11:24 UTC Modified: 2021-03-31 14:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: r dot wilczek at web-appz dot de Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 5.5.7 OS: Linux
Private report: No CVE-ID: None
 [2014-01-06 11:24 UTC] r dot wilczek at web-appz dot de
Description:
------------
Exceptions nesting a previous exception result in misleading error-reports.

In the test script below, Foo was actually caught and nested in an uncaught Bar.

The resulting fatal error errorneously suggests, that Foo was not caught.

Test script:
---------------
class Foo extends \Exception {};
class Bar extends \Exception {};

try {
    throw new Foo('Foo-message');
} catch (Foo $e) {
    throw new Bar('Bar-message', 4711, $e);
}

Expected result:
----------------
Fatal error: Uncaught exception 'Bar' with message 'Bar-message' in test.php on line 8

Foo: Foo-message in test.php on line 6

Call Stack:
0.0002     269440   1. {main}() test.php:0

Bar: Bar-message in test.php on line 8

Call Stack:
0.0002     269440   1. {main}() test.php:0

Actual result:
--------------
Fatal error: Uncaught exception 'Foo' with message 'Foo-message' in test.php on line 8

Foo: Foo-message in test.php on line 6

Call Stack:
0.0002     269440   1. {main}() test.php:0

Bar: Bar-message in test.php on line 8

Call Stack:
0.0002     269440   1. {main}() test.php:0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-31 14:43 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-03-31 14:43 UTC] cmb@php.net
> In the test script below, Foo was actually caught and nested in
> an uncaught Bar.

No, not really.  The Foo instance has been passed as $previous
argument to the Bar constructor, so the first exception is a Foo,
and the next exception is a Bar.  And the stacktrace displays the
exceptions in that order.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 11:01:29 2024 UTC