Code after a Using statement is Unreachable?

  • Thread starter Thread starter Kepler
  • Start date Start date
K

Kepler

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.
 
(e-mail address removed) (Kepler) wrote in
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.
 
Kepler said:
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.
 
Back
Top