Destructors and exceptions

David Turner dkturner at
Thu Jun 10 10:22:36 CEST 2004

kveretennicov at (Konstantin Veretennicov) wrote in message news:<5155aad2.0406090311.6a275231 at>...
> dkturner at (David Turner) wrote in message news:<e251b7ba.0406070651.1c98c09d at>...
> 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.

David Turner

More information about the Python-list mailing list