473,387 Members | 1,882 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,387 software developers and data experts.

Code after a Using statement is Unreachable?

I have a situation where I need to use a Using statement that creates
some records in a database. After that completes, if it completes, I
need to do some file creation. Any code I'm putting after the Using
statement gives a compiler warning of "Unreachable Code Detected", and
it never runs.

Why is this happening? I really don't want to put the file
manipulation code in the using statement because it's a transaction.
I also need for that code to occur after the aforementioned
transaction. To move it into the calling code would be really ugly,
since it belongs right within this function.

Any help will be appreciated.
Nov 16 '05 #1
3 5167
fe***********@hotmail.com (Kepler) wrote in
news:35**************************@posting.google.c om:
I have a situation where I need to use a Using statement that
creates some records in a database. After that completes, if it
completes, I need to do some file creation. Any code I'm
putting after the Using statement gives a compiler warning of
"Unreachable Code Detected", and it never runs.

Why is this happening? I really don't want to put the file
manipulation code in the using statement because it's a
transaction. I also need for that code to occur after the
aforementioned transaction. To move it into the calling code
would be really ugly, since it belongs right within this
function.


Without seeing the actual code, my best guess is there is an
unconditional "return" or "throw" statement in the using block. The
compiler sees this and issues the warning, since the code after
either one of those statements will never be executed.

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
Kepler <fe***********@hotmail.com> wrote:
I have a situation where I need to use a Using statement that creates
some records in a database. After that completes, if it completes, I
need to do some file creation. Any code I'm putting after the Using
statement gives a compiler warning of "Unreachable Code Detected", and
it never runs.

Why is this happening? I really don't want to put the file
manipulation code in the using statement because it's a transaction.
I also need for that code to occur after the aforementioned
transaction. To move it into the calling code would be really ugly,
since it belongs right within this function.


Please post the code - without seeing it, we can't know what's going
on.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Kepler <fe***********@hotmail.com> wrote:
I have a situation where I need to use a Using statement that creates
some records in a database. After that completes, if it completes, I
need to do some file creation. Any code I'm putting after the Using
statement gives a compiler warning of "Unreachable Code Detected", and
it never runs.

Why is this happening? I really don't want to put the file
manipulation code in the using statement because it's a transaction.
I also need for that code to occur after the aforementioned
transaction. To move it into the calling code would be really ugly,
since it belongs right within this function.


Please post the code - without seeing it, we can't know what's going
on.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

5
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
1
by: Kepler | last post by:
I have a situation where I need to use a Using statement that creates some records in a database. After that completes, if it completes, I need to do some file creation. Any code I'm putting...
4
by: SteadySteps | last post by:
Hi I migrated a project which compiles correctly on VC 6.0 to VS 2002. However now all I get several warning that all the statements within catch blocks are "unreachable code". How can I correct...
2
by: Hovik Melikyan | last post by:
This code produces a 'unreachable code' warning at line 16 (throw new X ...) with no visible reason: #include <string> class X { std::string msg;
6
by: dfetrow410 | last post by:
Can I do this in an if statement? public string getClass() { counta = counta + 1; if (counta < 2 ) {
8
by: teddysnips | last post by:
I'm new to C# - recent background mainly ASP.NET with VB.NET. Anyhoot, I needed to create a C# statement analogous to VB's IIf: VB.NET Dim e As Boolean e = IIf((CInt(MyVariable) 0), True,...
5
by: ev | last post by:
Hello, We are looking for any testing tool that is capable of checking code coverage for C,C ++ and Java code. Or at least for C and C++. We want to know how much (percentage) of our code written...
4
by: EmilyA | last post by:
Hi! I'm not that good at programming, so I was wondering if anyone could tell me why I'm getting an unreachable statement error for lines 18, 35, 68, and 86. import java.util.ArrayList; ...
1
by: HillBilly | last post by:
What does that error mean and why would each break statement be marked as unreachable? It implies the return will --always-- return some --thing-- if even null and no further processing can...
2
by: premMS143 | last post by:
Hi, I want to ping certain systems IP. Everytime I'm using DOS or Start --> Run mode for pinging different PCs. But its becoming very difficult. So I planned to develop a VB application to make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.