Professional Web Applications Themes

[PHP-DEV] finally again - PHP Development

Hello Cristiano, Friday, November 7, 2003, 4:15:06 PM, you wrote: > Hi Andi, >> I've stated my opinion in the past (search the archives) and I don't think >> it'd be feasible (nor critical) to implement this... > Do you agree that if we don't have finally we should have a way to catch all exceptions ? > Let me explain: > If you have a library that can raise a huge number of different > exceptions and you don't have finally, you should treat all exceptions at > the same try/catch block, and rethrow the exceptions that should propagate. ...

  1. #1

    Default Re: [PHP-DEV] Re: finally again

    Hello Cristiano,

    Friday, November 7, 2003, 4:15:06 PM, you wrote:
    > Hi Andi,
    >> I've stated my opinion in the past (search the archives) and I don't think
    >> it'd be feasible (nor critical) to implement this...
    > Do you agree that if we don't have finally we should have a way to catch all exceptions ?
    > Let me explain:
    > If you have a library that can raise a huge number of different
    > exceptions and you don't have finally, you should treat all exceptions at
    > the same try/catch block, and rethrow the exceptions that should propagate.
    > If you have finally, you can treat just the exceptions you need and
    > leave the others to be treated by the caller.
    > For example: if you don't have finally, don't have a "catch-all" clause
    > and lock some resouce inside a try block, you need to unlock it:
    > 1) in the try block: before every return statement after the resource allocation
    > 2) write a catch block for all possible exceptions that could be
    > raised and put the code before every return/throw statement (this could be
    > dozens of times)
    > 3) at the end of the try/catch block
    > If you have finally, you just put the same code inside the finally
    > block. No need to catch every exceptions one-by-one, no need to rethrow
    > exceptions that shouldn't be caught, no need to make code redundancy...
    > I know it's not critical, but IMHO it's important. I hope I was clear enough... :-)
    Regarding catch all the current idea of most developers i spoke to on the
    conf was that every exception should inherit from the buildin class
    exception. And therefor a simple catch(Exception $e) would do the trick.

    --
    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

  2. #2

    Default Re: [PHP-DEV] finally again

    Cristiano Duarte wrote:
    > Since we don't have finally, the current code is:
    In PHPUnit I use the following code

    public function runBare() {
    $catchedException = null;

    $this->setUp();

    try {
    $this->runTest();
    }

    catch (Exception $e) {
    $catchedException = $e;
    }

    $this->tearDown();

    // Workaround for missing "finally".
    if ($catchedException !== null) {
    throw $catchedException;
    }
    }

    Works fine for me [tm].

    --
    Sebastian Bergmann
    [url]http://sebastian-bergmann.de/[/url] [url]http://phpOpenTracker.de/[/url]

    Das Buch zu PHP 5: [url]http://professionelle-softwareentwicklung-mit-php5.de/[/url]

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

    Sebastian Bergmann Guest

Similar Threads

  1. [PHP-DEV] finally again
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: November 7th, 03:15 PM
  2. [PHP-DEV] finally again
    By Andrew Smith in forum PHP Development
    Replies: 0
    Last Post: October 26th, 02:07 PM
  3. [PHP-DEV] finally again
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: October 26th, 11:50 AM
  4. [PHP-DEV] finally again
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: October 24th, 08:21 PM
  5. [PHP-DEV] finally again
    By Cristiano Duarte in forum PHP Development
    Replies: 0
    Last Post: October 24th, 08:08 PM

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