Re: [Proposal] using statement enhancements

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 03/05/05


Date: Sat, 5 Mar 2005 17:45:53 -0000

cody <deutronium@gmx.de> wrote:
> Mostly always you use the using clause you deal with native ressources, so
> exception handlinjg is sooner or later inevitable.

Well, I don't agree that exception handling is in any way inevitable
*in the same scope as the using statement*, but I agree it happens.
 
> so why do we need to write
>
> try
> {
> using (File f = File.CreateText("bla.txt"))
> {
> }
> }catch (IOExcepion e)
> {
> }
>
> why don't we allow catch blocks directly attached to the using clause:
>
> using (File f = File.CreateText("bla.txt"))
> {
> }
> catch (IOExcepion e)
> {
> }

Yup, that would be nice for the cases where you *do* need to handle
exceptions at the same level.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too