Destructors and exceptions
David Turner
dkturner at telkomsa.net
Thu Jun 10 04:22:36 EDT 2004
kveretennicov at yahoo.com (Konstantin Veretennicov) wrote in message news:<5155aad2.0406090311.6a275231 at posting.google.com>...
> dkturner at telkomsa.net (David Turner) wrote in message news:<e251b7ba.0406070651.1c98c09d at posting.google.com>...
>
> using (Font f1 = new Font("Arial", 10), f2 = new Font("Arial", 12)) {
> // use f1 and f2...
> } // compiler will call Dispose on f1 and f2 either on exit or on exception;
> // not sure about order of disposal, but you can nest "using" anyway
>
> This saves you from trouble of coding try+finally+Dispose.
> BTW, does anybody know whether MS borrowed or invented this construct?
>
It still leaves the clean-up onus in the wrong place.
The "using" concept has been kicking around for a while. I think it's
a natural evolution of Lisp's with-foo-do idiom.
Regards
David Turner
More information about the Python-list
mailing list