""Jeffrey Tan[MSFT]"" wrote...
I think Peter's post has tell the main purpose and difference of Finally and Using.
You still should use "try" and "catch" blocks to handle the exceptions in
your program.
Well, at least after reading this thread, I don't feel so stupid about
asking the question. It appears a little more complicated than I first
thought.
It sounds like working with "try" and "catch" blocks inside a "using"
statement might be a good way to code. Is it safe to assume that in all
Framework classes, Dispose will always call Close (if it exists) on a
resource before releasing it?
Also, on a related subject, I was reading the documentation today on the
System.Data.ODBC namespace and I noticed in the example of OdbcDataReader
that it says "always call Close when done reading". Aside from the poor
English, this can be confusing.
Is there a easy way to determine whether a resource "must" be closed
explicitly (as opposed to preferably)? Maybe the documentation should read:
// ... always call Close when done reading.
// Close the connection when done with it ... (This time we really, really
mean it!)
Is there a simple way to determine which resources actually tie up native
resources and "must" be freed before going out of scope, short of sifting
through pages and pages of documentation? At first I thought maybe just
checking to see if a resource implements IDisposable would work, but I
notice DataReaders also implement that interface, so I guess it's not a good
indicator of what's really happening.
Thank you all for your help . . .