Are resources disposed even if an exception is thrown in a using block? [duplicate] Are resources disposed even if an exception is thrown in a using block? [duplicate] asp.net asp.net

Are resources disposed even if an exception is thrown in a using block? [duplicate]


The resources defined with the using statement were disposed, this is the main reason what using is good for.

The using statement ensures that Dispose is called even if an exception occurs while you are calling methods on the object. You can achieve the same result by putting the object inside a try block and then calling Dispose in a finally block; in fact, this is how the using statement is translated by the compiler.
http://msdn.microsoft.com/en-us/library/yh598w02%28v=VS.100%29.aspx


Yes, the resource of the using block will be disposed.


You wouldn't. Actually the using block is the same if you use try{}catch{}finally{} construction with Dispose method call in the finally block. So it will be called anyway.