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

 ID:                 32100
 Comment by:         joshuaswift 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:

Please add a finally block for exception handling


Previous Comments:
------------------------------------------------------------------------
[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

}

------------------------------------------------------------------------
[2010-09-21 09:47:37] c891652 at bofthew dot com

I feel nothing but disappointed that this bug got closed, without "any"
reason being written in the comments.

I also stand for including "finally". It's a well known Exception
Handling control block, and others in this bug have shown clearly why it
is needed.

------------------------------------------------------------------------
[2010-09-09 09:32:40] 128bitencrypted at gmail dot com

I noticed this bug because I have exactly the same problem atm and
finally could solve it. I found a great discussion about the "return"
problem and how it's solved in java. (IMHO I think that's the right
way)

stackoverflow dot com/questions/65035/in-java-does-return-trump-finally



In PHP it could be implemented like the following:



function example1()

{

   try {

      return "Return\n";

   } finally {

      echo "Finally\n";

   }

}



echo example1();



Output:

 Finally

 Return



And it's important that finally has the right to overwrite return.
(Although I think that there only a few cases where that would be
useful)



function example2()

{

   try {

      return "Return wins\n";

   } finally {

      return "Finally wins\n";

   }

}



echo example2();



Output:

 Finally wins



I hope that helps a bit more why finally would be a very useful in php!

Thanks.

------------------------------------------------------------------------
[2010-09-09 02:39:42] phplasma at gmail dot com

A finally block would indeed be useful, please reconsider.

------------------------------------------------------------------------
[2010-09-07 17:38:51] michael202 at gmx dot de

I also think that try-finally is useful.

try catch is no elegant replacement. 

Just needed it today again.

finally is more elegant than an other solution.



For example:



try {

  lots o' code

  if a return

  ..

  if b exit

  ..

} finally

  do somethin

}



Another solution to the "finally" problem is to use goto.

Not so elegant but not a bad thing according to Knuth.

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


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