php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33407 Invalid exception stack traces
Submitted: 2005-06-20 15:38 UTC Modified: 2005-06-22 09:11 UTC
From: tomas_matousek at hotmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.4 OS: WinXP
Private report: No CVE-ID:
 [2005-06-20 15:38 UTC] tomas_matousek at hotmail dot com
Description:
------------
Exception stack trace is created by the new operator and not when the exception is thrown. Is that an intention or a bug? I think it is bug and that it was intended to trace throwing of the exception since the stack trace message contains

"thrown in ..."

and not

"created in ...".

Reproduce code:
---------------
<?
function f()
{
  return new Exception("hello");
}

try
{
  $a = f();  
  throw $a;
}
catch(Exception $e)  
{
  throw $e;
}

Expected result:
----------------
Fatal error:  Uncaught exception 'Exception' with message 'hello' in C:\Web\$PhpTests\z.php:14
Stack trace:
#0 C:\Web\$PhpTests\z.php(14):
#1 {main}
  thrown in C:\Web\$PhpTests\z.php on line 14



Actual result:
--------------
Fatal error:  Uncaught exception 'Exception' with message 'hello' in C:\Web\$PhpTests\z.php:4
Stack trace:
#0 C:\Web\$PhpTests\z.php(4): f()
#1 C:\Web\$PhpTests\z.php(9): f()
#2 {main}
  thrown in C:\Web\$PhpTests\z.php on line 4



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-20 16:06 UTC] sniper@php.net
Don't keep on throwing it..it never get's there -> no bug

 [2005-06-20 20:55 UTC] tomas_matousek at hotmail dot com
I don't understand your comment. If you comment out the "throw $a;" statement the exception is not thrown. So the "new" expression doesn't throw it. However, if the exception is thrown by throw $a; why the stack trace is generated during the construction. That's definitely a bug.
 [2005-06-20 22:42 UTC] sniper@php.net
You throw in the last catch block but never catch that.

 [2005-06-21 08:53 UTC] tomas_matousek at hotmail dot com
Well, that's the point of all of that! I don't want to catch it because I want the stack trace to be shown. Alternatively, I can add try { } catch(Exception $f) { echo $f; } and the effect would be the same - a wrong stack trace would be printed. This has nothing to do with leaving exception uncaught.
 [2005-06-21 15:54 UTC] sfox@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

This is expected behaviour, as Jani said.  I'm therefore marking this report bogus.
 [2005-06-21 20:52 UTC] tomas_matousek at hotmail dot com
:-O
Well, you are saying that the feature is that if PHP reports
"thrown in C:\Web\$PhpTests\z.php on line 4"
than it means that the exception is created on line 4 and may be thrown elsewhere, right?
You are introducing a new meaning for the word "thrown" then! Okay, interesting feature.
 [2005-06-21 20:59 UTC] tomas_matousek at hotmail dot com
Do you really insist on that the stack trace should be created in the constructor of the exception and not by the throw statement? That's what I'm talking about.
 [2005-06-21 21:48 UTC] tony2001@php.net
Tomas, "throw" doesn't modify the exception, the call trace is generated in the moment when you instantiate the object.
We didn't invent it, take a look on Java, where it behaves in the same way.
Let's keep it this report bogus, as noone is going to change it.
 [2005-06-22 09:11 UTC] tomas_matousek at hotmail dot com
OK. I see. I didn't know that about Java. I know C# where it works differently. Then maybe you should change the word "thrown" to "created" because it is quite misleading (I was also mislead).
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 15:02:26 2014 UTC