3 ms·
But with a 'using' you can't catch an exception. So in production I end up using ( ;-) ) try catch finally.
by jmnicolas 13y ago
But with a 'using' you can't catch an exception.
So in production I end up using ( ;-) ) try catch finally.
- duncans 13y ago> with a 'using' you can't catch an exception [Citation needed]
- jmnicolas 13y agoOK let me rephrase it : the 'using' isn't catching the exceptions that are thrown inside its scope so you still have to use a 'catch' block. Then what's the point of having a 'using + catch' instead of a 'try catch finally' ?
- bluefinity 13y agoThe using block compiles to the equivalent of a try-finally block. If you want to catch an exception you can do it inside or outside the using block.
- ifross 13y agoThere are known issues with using "using". If the Dispose() call throws an exception in the finally block, then any exception that occurred in the within the using block is masked. The easy solution is to make sure that your Dispose() calls don't throw exceptions, unfortunately some of Microsoft's classes don't conform to this (e.g. WCF clients). The following MSDN article shows a case where they do not recommend using "using", and instead suggest explicitly using try-catch-finally: http://msdn.microsoft.com/en-us/library/aa355056.aspx http://msdn.microsoft.com/en-us/library/aa355056.aspx