From: Mateusz Przybylski <m dot przybylski at bkfmyjnie dot pl> Operating system: linux PHP version: 5.2.12 PHP Bug Type: Scripting Engine problem Bug description: Exception contains context from point of instantiation, not throw
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 bug report at http://bugs.php.net/?id=51067&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51067&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51067&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51067&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51067&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51067&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51067&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51067&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51067&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51067&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51067&r=support Expected behavior: http://bugs.php.net/fix.php?id=51067&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51067&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51067&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51067&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51067&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51067&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51067&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51067&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51067&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51067&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51067&r=mysqlcfg