Edit report at http://bugs.php.net/bug.php?id=32100&edit=1

 ID:                 32100
 Comment by:         tyra3l at gmail dot com
 Reported by:        ceefour at gauldong dot net
 Summary:            Request 'finally' support for exceptions
 Status:             Closed
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   *
 PHP Version:        5.*
 Block user comment: N
 Private report:     N

 New Comment:

+1 for adding the feature.

I'm a little bit disappointed that there are no comment from the php
core contributors on this issue except helly, and he didn't the first
which closed the, I could accept the fact, that this cannot be done by
technical reasons, but AFAIK it was rejected, because the core devs at
that time didn't used or understood the finally, so they said, that
nobody needs that.



http://marc.info/?l=php-internals&m=96773381231437&w=2



times has changed, try doesn't leaks memory nowdays (or does it?),
people got smarter, machines faster, maybe we could reconsider this
feature, and reject it based on the current situation, not from a vague
discussion from 10 years ago.



Tyrael


Previous Comments:
------------------------------------------------------------------------
[2011-02-17 14:14:33] hardyanto dot donny at gmail dot com

"finally" is very useful for using ADODB:



$db->StartTransaction();

try{

  ....

  ... any exception can occur here...

  ....

} finally {

  $db->CompleteTrans();

}



Even there is exception occur in try block, the CompleteTrans() always
be 

called.

------------------------------------------------------------------------
[2010-12-10 23:22:17] btsai at vrwarp dot com

Wouldn't the argument against finally from Bjarne Stroustrup's C++ Style
and Technique FAQ
(http://www2.research.att.com/~bs/bs_faq2.html#finally) hold true?



Basically, most good uses of finally are used for deallocating
resources. Another way would simply be to design an object that
represents the resource that automatically deallocates itself via the
destructor.

------------------------------------------------------------------------
[2010-12-10 16:08:56] marcus at lastcraft dot com

Hi...



The lack of finally causes us some crufty hard to debug code. The
comment about swallowing the source of the exception is not an academic
one - I've had grief over this.



As for exceptions being used for "control flow" - they are control flow,
that's the whole point. There is an antiquated argument from the C++ era
about this, mostly driven by outdated performance data. Exceptions are
not the same as errors, being more akin to a continuation when the usual
return path does not make sense.



Please, plase add finally to PHP as Java did to C++.



yours, Marcus

------------------------------------------------------------------------
[2010-12-10 12:02:15] joshuaswift at gmail dot com

Please add a finally block for exception handling

------------------------------------------------------------------------
[2010-10-03 07:58:34] matsubokkuri+php at gmail dot com

> c891652 at bofthew dot com

I'm disappointed about this request is closed without critical reasons.



The first comment author doesn't understand OOP correctly. The code
cannot raise 

exception to upper class.



The code would be following without finally statement.



// create temporary file

try{

  // write to temporary file

}catch(ConnectionException $e){

  // delete temporary file

}

// delete temporary file



The "delete temporary file" sentence would be duplicate.



I can write with finally as following without duplicate "delete
temporary file".

// create temporary file

try{

  // write to temporary file

}finally{

  // delete temporary file

}

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=32100


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=32100&edit=1

Reply via email to