Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93404 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10135 invoked from network); 19 May 2016 20:45:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 May 2016 20:45:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.218.54 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.218.54 mail-oi0-f54.google.com Received: from [209.85.218.54] ([209.85.218.54:33190] helo=mail-oi0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F1/34-05406-4D52E375 for ; Thu, 19 May 2016 16:45:09 -0400 Received: by mail-oi0-f54.google.com with SMTP id v145so148418697oie.0 for ; Thu, 19 May 2016 13:45:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to; bh=kY/Ak/HI5Zyl7KBpxtfYPwuSpvmieVA/iScXoAaR/oo=; b=uRlZqTYlg+cs/dVvY0ttWGyF4SzKGdX4jit514Hb74zRZNefcO2XBh6yyUkKgdpi1c Q1VTU6uPhoBj3mSrw7Tx0Rzv15gnfFp+citIYlwjWRttjhCyEPOtyzTYp3z4ktHArMbK ZEVE9sxunQIKIGciv+d7XgbGj0eGeLMI3zSe8pNOgCFVwYzBmoLcM2MyDm4oxgQMd9O0 16gW8Nqv2OqZGttsXRSdudskrUMtTJkgI73ZkegdgpXUVHt1XKibaiIFpAGLO6Vdghyd uzN51dVXgw1XluuaG++Sto9DYc79XJXvH4YNvsv/FVn9sfIfNdvCIHzLcvaPiyH03duC BMLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to; bh=kY/Ak/HI5Zyl7KBpxtfYPwuSpvmieVA/iScXoAaR/oo=; b=kCI8doQfic8QXfyhkgcp0s2gs7aDXSe2Fxfr90aHWz9EkyjAApymM2RQF7c4oCPPch gGHU6CbgR5qknvpUq8b6EiUZFBheaEXvgikG+Cg6hitGAyyR+gxuiHuhe4k2jju8DaHR q3vqHBSu4TJysiY7k2rPM51v1kJDEBH7VEFlKusWKnWml9e0bE0fFrlCTGjGQFd6fN6S S4IMa43l5vbv/0me3O1jWP1KINw80/1vXyVwA4V3YF92OtafHvAT596N4XLDBNXKruvP nXrD89OUcL5WW5c1LDk0jlxBshRZf6Iohw4mi7Rnd7oOA5zKJlk6Amk8/Vn9lZxEQvE0 BEOQ== X-Gm-Message-State: AOPr4FWbMi0KLjJCW33MqYYAPQAlH0w7PRTSGdDGTUXvVobr6ii2JfFwzjJytwafvobDThNJwfKWb+5VcAuIaA== MIME-Version: 1.0 X-Received: by 10.157.13.167 with SMTP id 36mr9919344ots.134.1463690704792; Thu, 19 May 2016 13:45:04 -0700 (PDT) Received: by 10.157.44.214 with HTTP; Thu, 19 May 2016 13:45:04 -0700 (PDT) In-Reply-To: References: <72f547d6-5fcf-3cd2-960d-cb612a429e47@php.net> <914fa1d6-9fae-51b2-9246-526eb5c01bc7@gmail.com> Date: Thu, 19 May 2016 22:45:04 +0200 Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Exception::getLine() From: rasmus@mindplay.dk (Rasmus Schultz) > True, but if you instead of throwing the same exception, threw a new one, you could capture both stacks. But you can never get the stack from the throw point of something created elsewhere. Precisely. I think there are good reasons why other languages collect the stack-trace on throw. Collecting the stack trace at construction would be correct if "throw new" was literally one statement - if the only time you could throw was at creation. That's not the case. We have deferred throws and factory methods for exceptions, and we have re-throws, so collecting the stack-trace at construction time doesn't work. Of course, fixing this would require a BC break, and nobody wants to even entertain the thought of those :-( On Thu, May 19, 2016 at 10:30 PM, Ryan Pallas wrote: > On Thu, May 19, 2016 at 1:47 PM, Rowan Collins > wrote: > >> On 19/05/2016 19:35, Rasmus Schultz wrote: >> >>> Technically, every throw is a new exception "flow" - even if you're > >>> recycling the Exception instance, it's the throw statement that > >>> >> starts the unique stack unwind from the throw site; it's where the > >> action happens. >> >> That's one interpretation, but it doesn't really hold up in all cases. >> Consider a catch statement that needs to filter more granularly than the >> class name; since you already mentioned PDO, I'll make an example with that: >> >> catch ( PDOException $e ) { >> if ( substr($e->getCode(), 0, 2) === '08' ) { >> $this->reconnect(); >> } else { >> throw $e; >> } >> } >> >> Of what value to a subsequent catch statement is the trace of that throw >> statement? And why does that "start a new exception flow", but if PDO threw >> different sub-classes, you could let one flow through unmodified by >> tightening the catch statement? >> > > True, but if you instead of throwing the same exception, threw a new one, > you could capture both stacks. But you can never get the stack from the > throw point of something created elsewhere. > > catch ( PDOException $e ) { > if ( substr($e->getCode(), 0, 2) === '08' ) { > $this->reconnect(); > } else { > throw new PDOException($e->getMessage(), $e->getCode(), $e); > } > } > > > >> Regards, >> -- >> Rowan Collins >> [IMSoP] >> >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>