Bug #64910 [Opn]: Line number of $e = new Exception vs. line number of throw $e
| From: | stas@php.net | Date: | Thu, 23 May 2013 20:34:28 +0000 |
| Subject: | Bug #64910 [Opn]: Line number of $e = new Exception vs. line number of throw $e | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-179101@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64910&edit=1
ID: 64910
Updated by: stas@php.net
Reported by: sebastian@php.net
Summary: Line number of $e = new Exception vs. line number of
throw $e
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 5.5Git-2013-05-23 (Git)
Block user comment: N
Private report: N
New Comment:
Consider however this:
try {
//stuff
} catch(Exception $e) {
$logger->log("Oops, exception!");
throw $e;
}
If we update file/line here, we lose original exception information and
file/line in the exception becomes useless. Right now, since 99.99% of
the code does "throw new", it is always useful.
So how would you propose to solve this?
Previous Comments:
------------------------------------------------------------------------
[2013-05-23 17:20:49] derick@php.net
I'd agree with this. Seems like a fix could be to update the file and line properties of the
exception in zend_throw_exception_internal/zend_throw_exception. Right now, it's set in the
object init of the Exception class only.
------------------------------------------------------------------------
[2013-05-23 16:07:15] sebastian@php.net
Description:
------------
The error message that is created for an uncaught exception as well as the stacktrace of an
exception list the number of the line on which the exception object was created. I would expect this
to be number of the line on which the exception is raised using the throw statement.
Also note that the documentation on this is inconsistent: the Exception::getLine() method is
documented with "Gets the line in which the exception occurred" whereas the
Exception::$line attribute is documented with "The line where the exception was created".
Test script:
---------------
<?php
$e = new Exception;
throw $e;
Expected result:
----------------
Fatal error: Uncaught exception 'Exception' in /home/sb/test.php:3
Stack trace:
#0 {main}
thrown in /home/sb/test.php on line 3
Actual result:
--------------
Fatal error: Uncaught exception 'Exception' in /home/sb/test.php:2
Stack trace:
#0 {main}
thrown in /home/sb/test.php on line 2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64910&edit=1