ID:               51067
 User updated by:  Mateusz Przybylski <m dot przybylski at bkfmyjn
 Reported By:      Mateusz Przybylski <m dot przybylski at bkfmyjn
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: linux
 PHP Version:      5.2.12
 New Comment:

> Please double-check the documentation available at

That's what I did first -_-

The documentation of class Exception states explicitly:

(Property) line  The line where the exception was thrown

Which is not the case, as per this bug report -- it holds the line
the instance was created in, not where it was thrown. Same goes for
the backtrace -- it originates from the point the instance of
exception was created, not from where it was thrown.


Previous Comments:
------------------------------------------------------------------------

[2010-02-17 10:43:19] j...@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



------------------------------------------------------------------------

[2010-02-17 09:31:33] Mateusz Przybylski <m dot przybylski at bkfmyjn

Description:
------------
An exception contains context (backtrace etc.) from the point it was
created, not where it was thrown.

I realize one could argue for either way, but IMHO it is more useful
to have it report point where it was thrown from than the place of
instantination.

Point in case: a function that translates certain error codes
returned from external system into exceptions. It makes no sense to
indicate the function itself as source of exceptional condition. The
function could be used by several functions interacting with the
remote system for common error signaling.

Example use: (NOT reproduce code)

function queryRemoteSystem($qry) {
        sendQry($qry);
        $r = readResponse();
        if ($r === false)
                throw remoteSystemException(); /* dis a function
call, yo */
}

function remoteSystemException() {
        switch (remoteErrorCode()) {
        case FOO:
                return new FooException();
        case BAR:
                return new BarException();
        default:
                return new GeneralRemoteException(); }
}



Reproduce code:
---------------
function creates($msg) {
        return new Exception($msg);
}

function throws() {
        throw creates('foo bar');
}

try {
        throws(); }
catch (Exception $e) {
        $trace = $e->getTrace();
        $firstFrame = $trace[0];
        echo 'Exception from function: '.$firstFrame['function']; }

Expected result:
----------------
Exception from function: throws

Actual result:
--------------
Exception from function: creates


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=51067&edit=1

  • #51067 [NE... Mateusz Przybylski <m dot przybylski at bkfmyjnie dot pl>
    • #5106... jani
    • #5106... Mateusz Przybylski <m dot przybylski at bkfmyjn

Reply via email to