🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

try catch question

#616
From: Tony Caduto
Date: Tue, 13 Jul 2004 05:35
38 lines
1867 bytes
Hi,
I have been playing around with C# and all works well, except for the try
except block.

Basicly
If I create a object like a  stream reader or writer and I have a
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.

I am I missing something or what is the point of having a try catch if you
can't reference object in it?

Another good example is a database transaction, you would want to rollback
in the try catch, but if the transaction object is not created inside the
try catch a exception is never raised and the rollback never happens, and if
you create inside the try, you can't reference the transaction in the catch.

I must be missing something.

Thanks,

--
Tony
Technical Details
Message-ID: <40f3748e@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news-out.ntli.net!newsrout1.ntli.net!news-in.ntli.net!ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,f80ee75cfac101b9,start
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Tony Caduto" <acaduto@amsoftwaredesign.com>
From: "Tony Caduto" <acaduto@amsoftwaredesign.com>
Newsgroups: borland.public.csharpbuilder.language.csharp
Subject: try catch question
Date: Tue, 13 Jul 2004 00:35:18 -0500
Lines: 40
Organization: M&I Trust
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 65.26.200.169
Message-ID: <40f3748e@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1089696910 65.26.200.169 (12 Jul 2004 22:35:10 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news-out.ntli.net!newsrout1.ntli.net!news-in.ntli.net!ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail