🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #617

Re: try catch question

#617
From: Jon Shemitz
Date: Tue, 13 Jul 2004 06:27
39 lines
2055 bytes
Tony Caduto wrote:

> StreamWriter mywriter new StreamWriter("pathtofile");
> try     {}
> catch   {}
> finally { mywriter.Close(); }
> 
> I get a error because it can't find mywriter in the catch or finally
> section.
> It seems like the try catch finally is in it's own namespace.

This isn't valid skeleton code - you need 
  StreamWriter mywriter = new StreamWriter("pathtofile");
not
  StreamWriter mywriter new StreamWriter("pathtofile");

Based on that error, I'm going to GUESS that what you really coded was 

  try     { StreamWriter mywriter new StreamWriter("pathtofile"); }
  catch   {}
  finally { mywriter.Close(); }

and the issue is that mywriter is only in scope within the try block.

  StreamWriter mywriter new StreamWriter("pathtofile");
  try     {} 
  catch   {}
  finally { mywriter.Close(); }

should work ... as should

  using (StreamWriter mywriter new StreamWriter("pathtofile"))
    try   {}
    catch {}

-- 

programmer, author  http://www.midnightbeach.com
and father          http://www.midnightbeach.com/hs
Technical Details
Message-ID: <40F380DB.819CE161@midnightbeach.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40f3748e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,f80ee75cfac101b9
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
Message-ID: <40F380DB.819CE161@midnightbeach.com>
Date: Mon, 12 Jul 2004 23:27:39 -0700
From: Jon Shemitz <jon@midnightbeach.com>
Reply-To: jon@midnightbeach.com
Organization: Midnight Beach
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
X-Accept-Language: en-US,en
MIME-Version: 1.0
Newsgroups: borland.public.csharpbuilder.language.csharp
Subject: Re: try catch question
References: <40f3748e@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 63.249.65.27
X-Trace: newsgroups.borland.com 1089700060 63.249.65.27 (12 Jul 2004 23:27:40 -0700)
Lines: 39
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail