On Wed, 2003-08-06 at 09:14, Marcus Börger wrote:
> Hello Cristiano,
[...]
> There's absolute no need for finally:
> 
> try {
> }
> catch (...) {
> }
> // here's you're finally code

Well, consider:

function foo() {
  try {
    // ...
  } catch (Exception $e) {
    // ...handle it...
    return false;
  } finally {
    // ...clean up...
  }

  // ...continue doing whatever...
  return true;
}

The cleanup code is always to be executed, the method should of course
not continue in case an exception was caught.

OK, I could write:

function foo() {
  try {
    // ...
  } catch (Exception $e) {
    // ...handle it...
  }

  // ...clean up ...
  if ($e) return false;

  // ...continue doing whatever...
  return true;
}

so all it boils down to is, I guess, syntactic sugar.

Evil programming language sourcecode below:)
----------------------------------------------------------------------------
[EMAIL PROTECTED]:~ > cat FinallyTest.java 
class FinallyTest {
  public static void main(String[] args) {
    boolean success= FinallyTest.test(args.length > 0);
    System.out.println("Success? " + success);
  }
  
  public static boolean test(boolean dothrow) {
    try {
      if (dothrow) {
        throw new Exception("Test");
      }
    } catch (Exception e) {
      e.printStackTrace();
      return false; 
    } finally {
      System.out.println("<<< In finally >>>");
    }
    System.out.println("OK");
    return true;
  }
}
[EMAIL PROTECTED]:~ > CLASSPATH="." java FinallyTest  
<<< In finally >>>
OK
Success? true
[EMAIL PROTECTED]:~ > CLASSPATH="." java FinallyTest 1
java.lang.Exception: Test
        at FinallyTest.test(FinallyTest.java:10)
        at FinallyTest.main(FinallyTest.java:3)
<<< In finally >>>
Success? false

- Timm


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to