php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45767 Wording mistake: "Next exception" is "Previous exception" really
Submitted: 2008-08-08 17:13 UTC Modified: 2010-12-22 13:54 UTC
From: david at grudl dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.0alpha1 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david at grudl dot com
New email:
PHP Version: OS:

 

 [2008-08-08 17:13 UTC] david at grudl dot com
Description:
------------
Chained exceptions are printed in uncommon order (from inner to outer exception). This makes me confused :-(

Reference: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html#printStackTrace()

Reproduce code:
---------------
    try {
        throw new FileNotFoundException("File not found.");

    } catch (FileNotFoundException $e) {

        throw new ConfigException("Missing configuration.", 0, $e);
    }

echo $e; // note $e is ConfigException!


Expected result:
----------------
exception 'FileNotFoundException' with message 'File not found.' in demo.php:8
Stack trace:
#0 demo.php(17): ...
#1 {main}

Next exception 'ConfigException' with message 'Missing configuration.' in demo.php:21
Stack trace:
#0 demo.php(28): ....
#1 {main}

Actual result:
--------------
exception 'ConfigException' with message 'Missing configuration.' in demo.php:21
Stack trace:
#0 demo.php(28): ....
#1 {main}

previous exception 'FileNotFoundException' with message 'File not found.' in demo.php:8
Stack trace:
#0 demo.php(17): ...
#1 {main}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-08 17:15 UTC] david at grudl dot com
Sorry - Expected result is Actual and Actual is Expected.
 [2008-08-09 20:45 UTC] johannes@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Your code handles an exception, throws a new one, which results in an "Fatal error: Uncaught exception", neither what you expect nor your actual code, please provide a proper reproduce case and explain the issue.
 [2008-08-10 08:39 UTC] david at grudl dot com
Reproduce code:

<?php

class LowException extends Exception
{
}

class HighException extends Exception
{
}

$e = new LowException("File not found.");

$e = new HighException("Missing configuration.", 0, $e);

echo $e; // $e is HighException instance
?>


Expected result:
----------------
exception 'HighException' with message 'Missing configuration.' in test.php:13 
Stack trace:
#0 {main}

Previous exception (or "Caused by") 'LowException' with message 'File not found.' in test.php:11
Stack trace:
#0 {main}


Actual result:
---------------
exception 'LowException' with message 'File not found.' in test.php:11
Stack trace:
#0 {main}

Next exception 'HighException' with message 'Missing configuration.' in test.php:13
Stack trace:
#0 {main}


Description:
------------
The first (and most appealing) line of textual output begins with "exception 'LowException' with message ...", but the printed exception is 'HighException'. This order makes output less evident.
 [2008-08-10 09:54 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You're assigning an object to a variable, then overwrite the variable with another and then echoing the variable holding the second object...
 [2008-08-11 15:03 UTC] david at grudl dot com
This is not bug, of course, this is feature request.
 [2008-08-11 15:18 UTC] lstrojny@php.net
At the end it is just a wording problem. "Next exception" should be "Previous exception" (which makes sense, than the method is called getPrevious()). Simple wording change, accepting it.
 [2008-08-11 16:04 UTC] david at grudl dot com
This is not only simple wording change, but order change. 

$e is instance of HighException (!)
$e has any inner/previous exception

echo $e prints:

exception 'LowException' with message ...
blah, blah, blah
...
...

HighException prints LowException at first line - it is not expectable. Stack traces are printed in reverse order, because it is preferable. Exceptions should be printed in reverse order too.
 [2010-12-22 13:54 UTC] johannes@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2010-12-22 13:54 UTC] johannes@php.net
The order is "closest first"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC