#51067 [Opn->Bgs]: Exception contains context from point of instantiation, not throw
| From: | jani@php.net | Date: | Wed, 17 Feb 2010 10:43:57 +0000 |
| Subject: | #51067 [Opn->Bgs]: Exception contains context from point of instantiation, not throw | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-147764@lists.php.net to get a copy of this message | ||
ID: 51067
Updated by: jani@php.net
Reported By: Mateusz Przybylski <m dot przybylski at bkfmyjn
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: linux
PHP Version: 5.2.12
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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