|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-02-17 10:43 UTC] jani@php.net
[2010-02-17 11:01 UTC] Mateusz Przybylski <m dot przybylski at bkfmyjn
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 22:00:01 2025 UTC |
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