On Thu, May 19, 2016 at 1:47 PM, Rowan Collins <rowan.coll...@gmail.com> 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 > >