Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67470 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46132 invoked from network); 23 May 2013 23:40:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 May 2013 23:40:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=jared.williams1@ntlworld.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jared.williams1@ntlworld.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ntlworld.com designates 81.103.221.47 as permitted sender) X-PHP-List-Original-Sender: jared.williams1@ntlworld.com X-Host-Fingerprint: 81.103.221.47 mtaout01-winn.ispmail.ntl.com Solaris 10 (beta) Received: from [81.103.221.47] ([81.103.221.47:53297] helo=mtaout01-winn.ispmail.ntl.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2B/26-16824-1F8AE915 for ; Thu, 23 May 2013 19:40:34 -0400 Received: from aamtaout01-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout01-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20130523234029.IQCN4711.mtaout01-winn.ispmail.ntl.com@aamtaout01-winn.ispmail.ntl.com> for ; Fri, 24 May 2013 00:40:29 +0100 Received: from p2 ([82.3.17.226]) by aamtaout01-winn.ispmail.ntl.com (InterMail vG.3.00.04.00 201-2196-133-20080908) with ESMTP id <20130523234029.HCFX27539.aamtaout01-winn.ispmail.ntl.com@p2> for ; Fri, 24 May 2013 00:40:29 +0100 To: Date: Fri, 24 May 2013 00:46:14 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.5510 In-Reply-To: <519E797D.7040405@php.net> x-mimeole: Produced By Microsoft MimeOLE V6.00.3790.4325 Thread-Index: Ac5X8sPbtcm2UtgITeuUzDOAHNIkWQAG5pUg Message-ID: <20130523234029.HCFX27539.aamtaout01-winn.ispmail.ntl.com@p2> X-Cloudmark-Analysis: v=1.1 cv=AUhbpHVS+xhHrj9wLCYAQoYnFLYUZdbP8UM0GmH2jwk= c=1 sm=0 a=WuKpm6uOyA0A:10 a=uObrxnre4hsA:10 a=oHf_AeXmDeQA:10 a=kj9zAlcOel0A:10 a=67BIL_jfAAAA:8 a=cDfDri19AeD__A_OF_UA:9 a=CjuIK1q_8ugA:10 a=UAYcVMrLiE8A:10 a=x35T2hBZrABxBCOl:21 a=bV-H8oau5lgrfbO8:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Subject: RE: [PHP-DEV] Bug #64910: Line number of $e = new Exception vs. line number of throw $e From: jared.williams1@ntlworld.com ("Jared Williams") References: <519E797D.7040405@php.net> > -----Original Message----- > From: Sebastian Bergmann [mailto:sebastian@php.net] > Sent: 23 May 2013 21:18 > To: internals@lists.php.net > Subject: [PHP-DEV] Bug #64910: Line number of $e = new > Exception vs. line number of throw $e > > Hi! > > 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. > > Derick agrees with me that this is a bug. We propose to > update the file and line properties of the exception object in the > zend_throw_exception_internal() and zend_throw_exception() functions. > > Would such a change be accepted? Does it require an RFC? > I agree that it should have been where the throw occurs, to allow for an ExceptionFactory type use. There is a method of making it better, but it's bit (rather a lot) gnarly. function createException($errno, $message, Exception $exception = null) { // Please forgive us for what we are about to do. // Fix up exceptions so they appear closer to where they are thrown $f = Closure::bind( function() { array_shift($this->trace); // createException_ $t = array_shift($this->trace); // createException $this->line = $t['line']; $this->file = $t['file']; return $this; }, $this->createException_($errno, $message, $exception), Exception::class); return $f(); } private function createException_($errno, $message, Exception $exception = null) { switch ($errno) { case 2002: return new ConnectException($message, $errno, $exception); case 2013: // Connection dropped. case 2006: // Gone away return new ConnectionDroppedException($message, $errno, $exception); /* .... */ default: return new DatabaseException($message, $errno, $exception); } } So throw $obj->createException(...); reports a more useful/accurate location. Jared