Timing is everything

I was doing some code reviews today. The particular project I was reviewing was doing COM-interop so one of the things I looked for was to make sure that any COM objects created were wrapped in a try/catch/finally block and those objects were properly released with Marshal.ReleaseComObject in the finally block.

I was thinking that the code would be cleaner if, inside the finally block, I could access variables created in the try block. Since you can't do that you're forced to define the variable outside the try/catch block.

Scott Wiltamuth just addressed a very similar question in his blog today.

No Comments