Article View: borland.public.csharpbuilder.language.csharp
Article #620Re: try catch question
From: Marc Rohloff TeamB
Date: Sat, 17 Jul 2004 15:23
Date: Sat, 17 Jul 2004 15:23
17 lines
1497 bytes
1497 bytes
On Sat, 17 Jul 2004 09:16:33 -0500, Colonel Tony wrote:
> This code will fail because it wont be able to find the mywriter.close()
> try { StreamWriter mywriter new StreamWriter("pathtofile"); }
> catch {}
> finally { mywriter.Close(); }
It is also incorrect.
If the 'new' fails then there is nothing to close.
Also the mywriter object will be invalid so calling mywriter.close
will generate a second (null reference) exception which will hide the
real exception.
--
Marc Rohloff [TeamB]
marc rohloff at myrealbox dot com
Technical Details
Message-ID:
<s3am1jplg0p9$.dlg@marcrohloff.40tude.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40f3748e@newsgroups.borland.com> <40F380DB.819CE161@midnightbeach.com> <40f934bb$1@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 From: "Marc Rohloff [TeamB]" <"on request"> Subject: Re: try catch question Newsgroups: borland.public.csharpbuilder.language.csharp User-Agent: 40tude_Dialog/2.0.12.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit References: <40f3748e@newsgroups.borland.com> <40F380DB.819CE161@midnightbeach.com> <40f934bb$1@newsgroups.borland.com> Date: Sat, 17 Jul 2004 11:23:16 -0400 Message-ID: <s3am1jplg0p9$.dlg@marcrohloff.40tude.net> NNTP-Posting-Host: 4.225.102.234 X-Trace: newsgroups.borland.com 1090077691 4.225.102.234 (17 Jul 2004 08:21:31 -0700) Lines: 17 X-Authenticated-User: mrohloff Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail