RE: [PHP-DEV] try..catch and finally
| From: | Wez Furlong | Date: | Fri, 01 Sep 2000 09:17:00 +0000 |
| Subject: | RE: [PHP-DEV] try..catch and finally | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-31552@lists.php.net to get a copy of this message | ||
: Zeev Said
> How about simply:
>
> try {
> ... modify contents ...
> } catch {
> ... any error recovery code here ...
> }
> ... cleanup code ...
>
>
> We're mostly gearing try..catch to allow users to handle errors, not
> perform cleanups.
Then a "roll-your-own" finally would look like this:
$rethrowme = null;
... allocate/get something important ...
try {
... use it (may fail) ...
}
catch ($except) {
$rethrowme = $except;
}
... free/unlock/release thing we got above ...
if ($rethrowme)
throw($rethrowme);
Not the nicest thing, but it will do without a real "finally" construct.
> >I understand if you don't implement a "finally" mechanism
> right away, but I
> >urge you to keep it in mind while writing the try..catch
> code; maybe someday
> >there will be hundreds of people asking for "finally" :-)
>
> We're not even implementing try..catch right away, let alone
> try..finally :)
>
> Zeev
Not before today anyway... :)