Am Donnerstag, den 28.02.2008, 11:16 +0000 schrieb Ian.Stark@[EMAIL PROTECTED]
> "David B. Benson" <dbenson@[EMAIL PROTECTED]
> writes:
> > On Feb 21, 6:05 am, rossb...@[EMAIL PROTECTED]
wrote:
> >> http://www.ps.uni-sb.de/alice/manual/sugar.html#finally
> >
> > Very nice! Thank you.
>
> There's a further refinement of this in the "exceptional syntax"
> proposed by Benton+Kennedy in JFP 11(4):394-410
>
> http://dx.doi.org/10.1017/S0956796801004099
> http://research.microsoft.com/~akenn/sml/ExceptionalSyntax.pdf
>
> where you want to identify code that runs only if an exception is not
> raised. Independently, Erlang introduced the same thing:
>
> try Expr of
> Pattern1 [when Guard1] -> Body1;
> ...
> catch
> ExceptionPattern1 [when ExceptionGuard1] -> ExceptionBody1
> ...
> after
> FinalBody
I have known this idiom as try-catch-finally (I think these keywords are
used in Delphi).
The point of this kind of code is that the 'after' (or 'finally') clause
is executed *even if the exception is not caught with a 'catch' clause*.
This spares you a lot of boilerplate code to catch all exceptions, undo
any resource allocations that happened during the 'try' clause, and then
either handle or rethrow the exception.
If resources are usually silently deallocated when an object is garbage
collected, this is still useful but slightly less so.
Regards,
Jo


|