No, both will be called. Just because an exception is thrown in an internal expression does not mean that the first is ignored.
The using statement is another syntax for:
var iDisposableItem = new Item(); try { ...... } finally { iDisposableItem.Dispose(); }
so in your example:
var iDisposableItem = new Item(); try { var iDisposableItem2 = new Item(); try { throws exception } finally { iDisposableItem2 .Dispose(); } } finally { iDisposableItem.Dispose(); }
Now, what should be noted and that you need to be careful is that everything that caused the first exception could cause problems with the external using statement when it calls Dispose() . An exception can cause (really any) an object to be in an error state, and a call to Dispose can lead to another other exception that "masks" the first. This is getting in WFC when using statements using : http://msdn.microsoft.com/en-us/library/aa355056.aspx
source share