Professional Web Applications Themes

[PHP-DEV] try/catch/FINALLY - PHP Development

Please, ignore this: > IMHO I think that an implementation start would be hooking the function exit > at the engine.. And read this instead: IMHO I think that an implementation start would be hooking the exit of the try statement even if its normal or has an exception thrown... Best regards, Cristiano Duarte "Cristiano Duarte" <cunha17uol.com.br> escreveu na mensagem news:20030806001540.7978.qmailpb1.pair.com... > Hi all, > > I know there was a lot of discussion about try/catch, but I will bring it up > again: > > What about finally ? > > I know someone posted that finally isn't necessary ...

  1. #1

    Default [PHP-DEV] Re: try/catch/FINALLY

    Please, ignore this:
    > IMHO I think that an implementation start would be hooking the function
    exit
    > at the engine..
    And read this instead:
    IMHO I think that an implementation start would be hooking the exit of the
    try statement even if its normal or has an exception thrown...

    Best regards,

    Cristiano Duarte

    "Cristiano Duarte" <cunha17uol.com.br> escreveu na mensagem
    news:20030806001540.7978.qmailpb1.pair.com...
    > Hi all,
    >
    > I know there was a lot of discussion about try/catch, but I will bring it
    up
    > again:
    >
    > What about finally ?
    >
    > I know someone posted that finally isn't necessary since PHP destroy all
    > variables and releases all resources at the end of the script. But if the
    > script is a PHP-GTK application or a standalone server aplication (like
    > CORBA)?
    >
    > Finally is very useful in situations where you must be certain that some
    > piece of code will be executed no matter what happens (a normal execution,
    a
    > return statement or an exception).
    >
    > IMHO I think that an implementation start would be hooking the function
    exit
    > at the engine..
    >
    > Cristiano Duarte
    >
    >


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

    Cristiano Duarte Guest

  2. #2

    Default Re: [PHP-DEV] try/catch/FINALLY

    Hello Cristiano,

    Wednesday, August 6, 2003, 2:15:39 AM, you wrote:

    CD> Hi all,

    CD> I know there was a lot of discussion about try/catch, but I will bring it up
    CD> again:

    CD> What about finally ?

    There's absolute no need for finally:

    try {
    }
    catch (...) {
    }
    // here's you're finally code


    --
    Best regards,
    Marcus mailto:hellyphp.net


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

    Marcus Börger Guest

  3. #3

    Default Re: [PHP-DEV] try/catch/FINALLY

    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:)
    ----------------------------------------------------------------------------
    thekidthekid:~ > 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;
    }
    }
    thekidthekid:~ > CLASSPATH="." java FinallyTest
    <<< In finally >>>
    OK
    Success? true
    thekidthekid:~ > 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: [url]http://www.php.net/unsub.php[/url]

    Timm Friebe Guest

  4. #4

    Default Re: [PHP-DEV] try/catch/FINALLY

    The most important thing missing from this is that you cannot rethrow the
    exception from the point where you suggest to place the finally code :-)

    --Wez.
    > There's absolute no need for finally:
    >
    > try {
    > }
    > catch (...) {
    > }
    > // here's you're finally code


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

    Wez Furlong Guest

  5. #5

    Default Re: [PHP-DEV] try/catch/FINALLY

    Hello Cristiano,

    Wednesday, August 6, 2003, 6:15:39 AM, you wrote:

    It would be much better if user will have to put method's throws in
    method's declaration imho( see my reply to Marcus ).

    --
    Best regards,
    Simeon mailto:xinewmail.ru


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

    Simeon Koptelov Guest

  6. #6

    Default Re: [PHP-DEV] try/catch/FINALLY


    On Wednesday, August 6, 2003, at 03:14 AM, Marcus B=F6rger wrote:
    > There's absolute no need for finally:
    PHP doesn't necessarily control every resources you might want to=20
    deallocate.

    mysql_query('LOCK ...');
    try {
    ... do stuff
    } finally {
    mysql_query('UNLOCK...');
    }
    ... do more stuff=


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

    Jeff Moore Guest

Similar Threads

  1. [PHP-DEV] finally again
    By Andrew Smith in forum PHP Development
    Replies: 0
    Last Post: October 26th, 02:07 PM
  2. The problem with Try Catch Finally...
    By VB Programmer in forum ASP.NET General
    Replies: 23
    Last Post: August 15th, 01:55 PM
  3. Question: Try,Catch,Finally
    By VB Programmer in forum ASP.NET General
    Replies: 1
    Last Post: August 7th, 07:27 PM
  4. Re[2]: [PHP-DEV] try/catch/FINALLY
    By Simeon Koptelov in forum PHP Programming
    Replies: 0
    Last Post: August 6th, 07:55 AM
  5. [PHP-DEV] try/catch/FINALLY
    By Cristiano Duarte in forum PHP Programming
    Replies: 0
    Last Post: August 6th, 12:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139