473,320 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using Statement & Catch

To catch an exception associated with resources within a Using block, does
the Catch block go within the scope of the Using block or following it?

If within the scope of the Using block, what about nested Using statements?
Will a Catch block in the innermost Using block catch all exceptions?

--
Regards,

Fred Chateau
fchateauAtComcastDotNet
Sep 5 '06 #1
3 1805
>To catch an exception associated with resources within a Using block, does
>the Catch block go within the scope of the Using block or following it?
Depends on what you want. If you put it inside the using block, it
will not catch exceptions thrown by the Dispose method. If you put a
try/catch around the using block, the resource variable will be out of
scope and not usable from the catch block.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 5 '06 #2
"Fred Chateau" <fc******@127.0.0.1wrote ...
To catch an exception associated with resources within a Using block, does
the Catch block go within the scope of the Using block or following it?
Never mind...

I don't think you can use a Catch statement without a corresponding Try
statement, or at least Intellisense wouldn't accept it without one.

Regards,

Fred Chateau
Sep 5 '06 #3
Mattias,
Depends on what you want. If you put it inside the using block, it
will not catch exceptions thrown by the Dispose method. If you put a
try/catch around the using block, the resource variable will be out of
scope and not usable from the catch block.
Very secure answered.

:-)

Cor
Sep 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
5
by: charliewest | last post by:
I've implemented the USING statement to ensure that my newly created sql connection closes when my method is finished using it. The USING statement is wrapped in try/catch error handling statement....
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
4
by: steingold | last post by:
Hi all I'm using DB2 UDB v8.2 on linux. After minimizing the code in order to isolate the problem, I have a simple jdbc client that executes the following SQL statement in loop : SELECT * FROM...
4
by: cj | last post by:
my old code Try Dim sw As New System.io.StreamWriter(fileName, True) sw.WriteLine(strToWrite) sw.Close() Catch End Try my new code
5
by: Nirmala123 | last post by:
hi... I want to sort the table using combobox values. I give the code here. address.html: <html> <head> <title>Add a new entry</title> </head>
4
by: Mike | last post by:
All the code samples I can find show using on its own or try... catch.. ..finally on its own. Will the following cover me properly in terms of handling errors and cleaning up? string conns =...
15
by: tshad | last post by:
Do I still need to close an object in a finally statement after a catch if it is part of a using statement? For example: FileStream fs = null; try { using (FileInfo fInfo = new...
3
by: CSharper | last post by:
I have a using statement something like the following try { using(SqlConnection cnn = ...) { } catch(Exception e1) { }
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.