Stephen Coakley: > So what should be the desired behavior, in regard to bug #68270? One > possible behavior would be to, if an exception is thrown inside a > finally block, to attach the uncaught exception from the try block via > the addSupressed() method. The last exception is thrown, and the > exception in the try block is still not lost. Such an alternative could > be bundled with the RFC.
I also like that idea very much that the try-exception is not lost in this case. So I would agree defining this behaviour can be part of the RFC as well. Also the current behaviour is nowhere documented so changing it can be considered as backward compatible (plus it would close bug #68270). > try { > try { > throw new Exception("Exception 1"); > } finally { > throw new Exception("Exception 2"); > } > } catch (Throwable $e) { > var_dump($e->getSupressed()); > } > > we would have $e be exception 2, and $e->getSupressed() return exception 1. Ack. But the original idea was that Throwable::getSupressed() will return a *list* of exceptions. You probably didn't change that intentionally. The try-finally scenario involves only one supressed exception. I'd like to see a possibility to add more supressed exceptions, as described in the initial mail for e.g. a use case where just more resources need to be closed. Now that try-finally is part of the scope as well, I'd like to add the case that a supressed exception might be thrown from a catch block as well: try { throw new Exception("Exception 1"); } catch (Exception $e) { throw new Exception("Exception 2", 0, $e); } finally { throw new Exception("Exception 3"); } So in this case the resulting exception would be exception 3, which has exception 2 as a supressed exception. Exception 1 is as already defined the previous exception of exception 2. > The more I think about it, the better the idea sounds. Good thought, Good to hear that the idea finds acceptance. Also I like the evolving of it. I guess drafting a RFC might be an option then. I will let this idea brew a bit and then start with that, assuming doing so is fine. Markus Malkusch -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php