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

Try... Catch... Finally blocks

Just a quick and probably daft question...

Isn't the code;

Try
DoSomething()
Catch e As Exception
HandleError(e)
Finally
DoThisAtTheEnd()
End Try

functionally identical to...

Try
DoSomething()
Catch e As Exception
HandleError(e)
End Try
DoThisAtTheEnd()

What I'm getting at, is that I don't really see the point of the Finally statement! Surely after the Catching and handling has been dealt with, the code will move on to whatever is after the End Try anyway?!?
Your comments appreciated... :D
____________________________________________
The Grim Reaper
Nov 23 '05 #1
26 2523
Yes, unless you end up with an error inside of your HandleError:

Try
DoSomething()
Catch e As Exception
HandleError(e)
Finally
'This will still run
DoThisAtTheEnd()
End Try
Try
DoSomething()
Catch e As Exception
HandleError(e)
End Try

'This will not run now
DoThisAtTheEnd()

Private Sub HandleError(ByRef ex As Exception)
Dim i As Integer = 1
Dim j as Integer = 0

'Intentional divide by zero error
'simulates bad handling, like logging routine cannot
'access database server (SQL Error?)
Dim k as Integer = i/j

End Sub

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
"Grim Reaper" <gdewdneyatsilvertechcouk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Just a quick and probably daft question...

Isn't the code;

Try
DoSomething()
Catch e As Exception
HandleError(e)
Finally
DoThisAtTheEnd()
End Try

functionally identical to...

Try
DoSomething()
Catch e As Exception
HandleError(e)
End Try
DoThisAtTheEnd()

What I'm getting at, is that I don't really see the point of the Finally
statement! Surely after the Catching and handling has been dealt with, the
code will move on to whatever is after the End Try anyway?!?
Your comments appreciated... :D
____________________________________________
The Grim Reaper
Nov 23 '05 #2
Ahhhh.... I see.
I was obviously still inside my box.. (it is Monday after all)

Cheers!
_____________________________________
The Grim Reaper

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:On**************@TK2MSFTNGP12.phx.gbl...
Yes, unless you end up with an error inside of your HandleError:

Try
DoSomething()
Catch e As Exception
HandleError(e)
Finally
'This will still run
DoThisAtTheEnd()
End Try
Try
DoSomething()
Catch e As Exception
HandleError(e)
End Try

'This will not run now
DoThisAtTheEnd()

Private Sub HandleError(ByRef ex As Exception)
Dim i As Integer = 1
Dim j as Integer = 0

'Intentional divide by zero error
'simulates bad handling, like logging routine cannot
'access database server (SQL Error?)
Dim k as Integer = i/j

End Sub

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
"Grim Reaper" <gdewdneyatsilvertechcouk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Just a quick and probably daft question...

Isn't the code;

Try
DoSomething()
Catch e As Exception
HandleError(e)
Finally
DoThisAtTheEnd()
End Try

functionally identical to...

Try
DoSomething()
Catch e As Exception
HandleError(e)
End Try
DoThisAtTheEnd()

What I'm getting at, is that I don't really see the point of the Finally
statement! Surely after the Catching and handling has been dealt with,
the code will move on to whatever is after the End Try anyway?!?
Your comments appreciated... :D
____________________________________________
The Grim Reaper

Nov 23 '05 #3
> What I'm getting at, is that I don't really see the point of the Finally
statement!

1. In a Finally clause, any Dim'ed variables will go out of scope when the
Try block finishes.

2. If you exit a try block with a Goto, the Finally block will be executed
before the Goto (Documentation says this, I never tried it out).

Nov 23 '05 #4
"AMercer" <AM*****@discussions.microsoft.com> schrieb:
2. If you exit a try block with a Goto, the Finally block will be
executed
before the Goto (Documentation says this, I never tried it out).


That's true. It's even executed if you exit procedure using 'Return' or
'Exit...'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #5
Now that IS interesting...
I don't think I would put a Return or Exit statement inside a Try block in
the first place,
but that certainly could cause problems.

So finally is basically saying "do this before you leave the block -
whatever".
______________________________________
The Pished Reaper

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ue*************@TK2MSFTNGP15.phx.gbl...
"AMercer" <AM*****@discussions.microsoft.com> schrieb:
2. If you exit a try block with a Goto, the Finally block will be
executed
before the Goto (Documentation says this, I never tried it out).


That's true. It's even executed if you exit procedure using 'Return' or
'Exit...'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #6
Another good thing to put in your finally is your disposal or closing
of objects. Great for DB Connections.

Try
dim SqlCn as SqlConnection..

'Excute your statement
Catch Ex as Exception
throw ex
Finally
if SqlCn.ConnectionState = Open Then SqlCn.Close
SqlCn.dispose
End Try

This will always guarantee that you have a closed connection to your
database. This saves you from having to write that code twice, say in
the Try and in the Catch.
I use the Finally all the time.

Derek Woo

Nov 23 '05 #7
Good idea,

Peter

"wooster11" <wo*******@yahoo.com>
wrote:11*********************@g44g2000cwa.googlegr oups.com...
Another good thing to put in your finally is your disposal or closing
of objects. Great for DB Connections.

Try
dim SqlCn as SqlConnection..

'Excute your statement
Catch Ex as Exception
throw ex
Finally
if SqlCn.ConnectionState = Open Then SqlCn.Close
SqlCn.dispose
End Try

This will always guarantee that you have a closed connection to your
database. This saves you from having to write that code twice, say in
the Try and in the Catch.
I use the Finally all the time.

Derek Woo

Nov 23 '05 #8
wooster11 wrote:
Another good thing to put in your finally is your disposal or closing
of objects. Great for DB Connections.

Try
dim SqlCn as SqlConnection..

'Excute your statement
Catch Ex as Exception
throw ex
Finally
if SqlCn.ConnectionState = Open Then SqlCn.Close
SqlCn.dispose
End Try

This will always guarantee that you have a closed connection to your
database. This saves you from having to write that code twice, say in
the Try and in the Catch.
I use the Finally all the time.

Derek Woo


Just thought I'd point out - that the Catch in your example is really not
necessary, since your just re-throwing the exception. I would probably
just do this:

Dim connection As SqlConnection = Nothing

Try
' create the connection
' execute your stuff
Finally
' dispose of your objects
End Try

The functional result is that the exception is thrown, just as yours does
and your resources are still released. I do this all the time in my C#
code :)

--
Tom Shelton [MVP]
Nov 23 '05 #9
I thought I'd read somewhere that

Throw ex

behaved differently than just

Throw

all by itself?

Greg

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
wooster11 wrote:
Another good thing to put in your finally is your disposal or closing
of objects. Great for DB Connections.

Try
dim SqlCn as SqlConnection..

'Excute your statement
Catch Ex as Exception
throw ex
Finally
if SqlCn.ConnectionState = Open Then SqlCn.Close
SqlCn.dispose
End Try

This will always guarantee that you have a closed connection to your
database. This saves you from having to write that code twice, say in
the Try and in the Catch.
I use the Finally all the time.

Derek Woo


Just thought I'd point out - that the Catch in your example is really not
necessary, since your just re-throwing the exception. I would probably
just do this:

Dim connection As SqlConnection = Nothing

Try
' create the connection
' execute your stuff
Finally
' dispose of your objects
End Try

The functional result is that the exception is thrown, just as yours does
and your resources are still released. I do this all the time in my C#
code :)

--
Tom Shelton [MVP]

Nov 23 '05 #10
http://www.codeproject.com/dotnet/ex...tpractices.asp
Don't clear the stack trace when re-throwing an exception
The stack trace is one of the most useful information that an exception
carries. Often, we need to put some exception handling on catch blocks
(e.g., to rollback a transaction) and re-throw the exception. See the right
(and the wrong) way of doing it: The wrong way:
try
{
// Some code that throws an exception
}
catch (Exception ex)
{
// some code that handles the exception
throw ex;
}
Why is this wrong? Because, when you examine the stack trace, the point of
the exception will be the line of the "throw ex;", hiding the real error
location. Try it.

try
{
// Some code that throws an exception
}
catch (Exception ex)
{
// some code that handles the exception
throw;
}
What has changed? Instead of "throw ex;", which will throw a new exception
and clear the stack trace, we have simply "throw;". If you don't specify the
exception, the throw statement will simply rethrow the very same exception
the catch statement caught. This will keep your stack trace intact, but
still allows you to put code in your catch blocks.

"Greg Burns" <bl*******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I thought I'd read somewhere that

Throw ex

behaved differently than just

Throw

all by itself?

Greg

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
wooster11 wrote:
Another good thing to put in your finally is your disposal or closing
of objects. Great for DB Connections.

Try
dim SqlCn as SqlConnection..

'Excute your statement
Catch Ex as Exception
throw ex
Finally
if SqlCn.ConnectionState = Open Then SqlCn.Close
SqlCn.dispose
End Try

This will always guarantee that you have a closed connection to your
database. This saves you from having to write that code twice, say in
the Try and in the Catch.
I use the Finally all the time.

Derek Woo


Just thought I'd point out - that the Catch in your example is really not
necessary, since your just re-throwing the exception. I would probably
just do this:

Dim connection As SqlConnection = Nothing

Try
' create the connection
' execute your stuff
Finally
' dispose of your objects
End Try

The functional result is that the exception is thrown, just as yours does
and your resources are still released. I do this all the time in my C#
code :)

--
Tom Shelton [MVP]


Nov 23 '05 #11
Greg Burns wrote:
I thought I'd read somewhere that

Throw ex

behaved differently than just

Throw

all by itself?

Greg


As you pointed out, there is a difference in how the stack trace is affected
by doing a Throw vs. Throw ex. I use Throw when I need to do something
with an error of course, before I send it up the stack - but often times, I
really don't need to do anything with the exception except let it flow up
the stack... That's where the optional Catch comes in, since it
essentially preserves the stack, but lets you do any cleanup that needs to
be done.

--
Tom Shelton [MVP]
Nov 23 '05 #12
Tom,
And with VB 2005 you can simplify it to:

| Using connection As SqlConnection = ... create the connection
| ' execute your stuff
| End Try
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
| wooster11 wrote:
|
| > Another good thing to put in your finally is your disposal or closing
| > of objects. Great for DB Connections.
| >
| > Try
| > dim SqlCn as SqlConnection..
| >
| > 'Excute your statement
| > Catch Ex as Exception
| > throw ex
| > Finally
| > if SqlCn.ConnectionState = Open Then SqlCn.Close
| > SqlCn.dispose
| > End Try
| >
| > This will always guarantee that you have a closed connection to your
| > database. This saves you from having to write that code twice, say in
| > the Try and in the Catch.
| > I use the Finally all the time.
| >
| > Derek Woo
|
| Just thought I'd point out - that the Catch in your example is really not
| necessary, since your just re-throwing the exception. I would probably
| just do this:
|
| Dim connection As SqlConnection = Nothing
|
| Try
| ' create the connection
| ' execute your stuff
| Finally
| ' dispose of your objects
| End Try
|
| The functional result is that the exception is thrown, just as yours does
| and your resources are still released. I do this all the time in my C#
| code :)
|
| --
| Tom Shelton [MVP]
Nov 23 '05 #13
Jay B. Harlow [MVP - Outlook] wrote:
Tom,
And with VB 2005 you can simplify it to:

| Using connection As SqlConnection = ... create the connection
| ' execute your stuff
| End Try


True... I do use using sometimes in C#, but I find that if there are a lot
of resources to be disposed, then it actually can be a hinderance to
readability if they are nested at multiple levels (since, you can only have
objects of the same type in the using statement):

using (SqlConnection connection = new ....)
{
using (SqlCommand command = new ....)
{
using (DataSet ds = new DataSet)
{
// blah
}
}
}

I can create multiple connections in the first block by putting them in a
comma separated list - but, I can't put both the connection and the command
in the same using statement... Hmmm, does VB2005 have this limitation? It
seems to me the only requirement is that the object should be of type
IDisposable (implement the interface :)....

--
Tom Shelton [MVP]
Nov 23 '05 #14
Tom,

A dataset has AFAIK not any unmanaged resource, so in my opinon the extra
disposing of that has not much sense.

A point that I find a problem with the "using" in this situations is that
you cannot catch any updating error, not even a concurrency error, which
makes that in my eyes than there is needed, that globaly should be tested on
a wide range of error situations.

Just my opinon.

Cor
Nov 23 '05 #15
"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
1. In a Finally clause, any Dim'ed variables will go out of scope
when the Try block finishes.


Other than it "looking" right to the human reader, can anyone suggest
why it does this? Limiting the scope to within the Try .. End Try
construct /as a whole/ would make so much more sense, especially
because you want to use Finally to clean things up, but can't because
a variable Dim'd within the Try goes out of scope when the code "hits"
the Catch (or Finally!) clause, and, therefore, no longer exists!

Yours, Perplexed,
Phill W.
Nov 23 '05 #16
Tom,
VB allows objects of different types:

Using connection As SqlConnection = ..., command As SqlCommand =
...., ds As New DataSet

End Using

I didn't realize C# had that restriction, what an odd restriction, although
I can see where it comes from.
FWIW: The above is equalivent to:

Using connection As SqlConnection = ...
Using command As SqlCommand = ...
Using ds As New DataSet

End Using
End Using
End Using

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:e6**************@TK2MSFTNGP14.phx.gbl...
| Jay B. Harlow [MVP - Outlook] wrote:
|
| > Tom,
| > And with VB 2005 you can simplify it to:
| >
| > | Using connection As SqlConnection = ... create the connection
| > | ' execute your stuff
| > | End Try
| >
| >
|
| True... I do use using sometimes in C#, but I find that if there are a
lot
| of resources to be disposed, then it actually can be a hinderance to
| readability if they are nested at multiple levels (since, you can only
have
| objects of the same type in the using statement):
|
| using (SqlConnection connection = new ....)
| {
| using (SqlCommand command = new ....)
| {
| using (DataSet ds = new DataSet)
| {
| // blah
| }
| }
| }
|
| I can create multiple connections in the first block by putting them in a
| comma separated list - but, I can't put both the connection and the
command
| in the same using statement... Hmmm, does VB2005 have this limitation?
It
| seems to me the only requirement is that the object should be of type
| IDisposable (implement the interface :)....
|
| --
| Tom Shelton [MVP]
Nov 23 '05 #17
Tom,
True... I do use using sometimes in C#, but I find that if there are a lot
of resources to be disposed, then it actually can be a hinderance to
readability if they are nested at multiple levels (since, you can only have
objects of the same type in the using statement):

using (SqlConnection connection = new ....)
{
using (SqlCommand command = new ....)
{
using (DataSet ds = new DataSet)
{
// blah
}
}
}

Don't you have the same readability problem with nested try/catch
blocks?

BTW you don't have to indent each level

using (SqlConnection connection = new ....)
using (SqlCommand command = new ....)
using (DataSet ds = new DataSet)
{
// blah
}
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 23 '05 #18
Mattias,
Ah! I was thinking there was a way...

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:e1**************@tk2msftngp13.phx.gbl...
| Tom,
|
| >True... I do use using sometimes in C#, but I find that if there are a
lot
| >of resources to be disposed, then it actually can be a hinderance to
| >readability if they are nested at multiple levels (since, you can only
have
| >objects of the same type in the using statement):
| >
| >using (SqlConnection connection = new ....)
| >{
| > using (SqlCommand command = new ....)
| > {
| > using (DataSet ds = new DataSet)
| > {
| > // blah
| > }
| > }
| >}
|
|
| Don't you have the same readability problem with nested try/catch
| blocks?
|
| BTW you don't have to indent each level
|
| using (SqlConnection connection = new ....)
| using (SqlCommand command = new ....)
| using (DataSet ds = new DataSet)
| {
| // blah
| }
|
|
| Mattias
|
| --
| Mattias Sjögren [MVP] mattias @ mvps.org
| http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| Please reply only to the newsgroup.
Nov 23 '05 #19
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
| BTW you don't have to indent each level
|
| using (SqlConnection connection = new ....)
| using (SqlCommand command = new ....)
| using (DataSet ds = new DataSet)
| {
| // blah
| }

Ah! I was thinking there was a way...


Mhm... I still think the way chosen in VB.NET is better than those of C#.
The code above requires an additional indentation rule for the 'using'
statement.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #20
Herfried,
Yes I agree, I think VB's method is "cleaner" & possibly more discoverable.
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> schrieb:
| > | BTW you don't have to indent each level
| > |
| > | using (SqlConnection connection = new ....)
| > | using (SqlCommand command = new ....)
| > | using (DataSet ds = new DataSet)
| > | {
| > | // blah
| > | }
| >
| > Ah! I was thinking there was a way...
|
| Mhm... I still think the way chosen in VB.NET is better than those of C#.
| The code above requires an additional indentation rule for the 'using'
| statement.
|
| --
| M S Herfried K. Wagner
| M V P <URL:http://dotnet.mvps.org/>
| V B <URL:http://classicvb.org/petition/>
|
Nov 23 '05 #21
Mattias Sjögren wrote:
Tom,
True... I do use using sometimes in C#, but I find that if there are a
lot of resources to be disposed, then it actually can be a hinderance to
readability if they are nested at multiple levels (since, you can only
have objects of the same type in the using statement):

using (SqlConnection connection = new ....)
{
using (SqlCommand command = new ....)
{
using (DataSet ds = new DataSet)
{
// blah
}
}
}

Don't you have the same readability problem with nested try/catch
blocks?


Yes, but I would really have them...

SqlConnection connection = null;
SqlCommand command = null;
DataSet ds = null;

try
{
// blah
}
catch
{
// blah
}
finally
{
if (ds != null) ds.Dispose ();
if (command != null) command.Dispose ();
if (connection != null) connection.Dispose ();
}

Obviously contrived - but, I really don't nest try/catch blocks to much.
BTW you don't have to indent each level


I realize that - but, it's sort of an old habbit from perl (not leaving
dangling braces, I mean :) Still - I think the C# using statment would be
better off if it allowed multiple types in the list. Basically, they
should just be treated as IDisposable.

--
Tom Shelton [MVP]
Nov 23 '05 #22
Cor Ligthert [MVP] wrote:
Tom,

A dataset has AFAIK not any unmanaged resource, so in my opinon the extra
disposing of that has not much sense.

A point that I find a problem with the "using" in this situations is that
you cannot catch any updating error, not even a concurrency error, which
makes that in my eyes than there is needed, that globaly should be tested
on a wide range of error situations.

Just my opinon.

Cor


Probably valid, Cor. I'm not much of a data guy... I simply used the
objects being referenced in the post I was responding to.

--
Tom Shelton [MVP]
Nov 23 '05 #23
Tom,
Don't you have the same readability problem with nested try/catch
blocks?


Yes, but I would really have them...

SqlConnection connection = null;
SqlCommand command = null;
DataSet ds = null;

try
{
// blah
}
catch
{
// blah
}
finally
{
if (ds != null) ds.Dispose ();
if (command != null) command.Dispose ();
if (connection != null) connection.Dispose ();
}

OK but then the code is no longer equivalent to what you get with
using blocks. If ds.Dispose() throws an exception the command and
connection will be left undisposed if you don't have the nesting.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 23 '05 #24
Mattias Sjögren wrote:
Tom,
Don't you have the same readability problem with nested try/catch
blocks?


Yes, but I would really have them...

SqlConnection connection = null;
SqlCommand command = null;
DataSet ds = null;

try
{
// blah
}
catch
{
// blah
}
finally
{
if (ds != null) ds.Dispose ();
if (command != null) command.Dispose ();
if (connection != null) connection.Dispose ();
}

OK but then the code is no longer equivalent to what you get with
using blocks. If ds.Dispose() throws an exception the command and
connection will be left undisposed if you don't have the nesting.
Mattias


Good point...

--
Tom Shelton [MVP]
Nov 23 '05 #25
Ever wish you'd just kept quiet about something?? :D
_______________________________________
The Grim Reaper

"Tom Shelton" <to*@YOUKNOWTHEDRILLmtogden.com> wrote in message
news:O8*************@TK2MSFTNGP10.phx.gbl...
Mattias Sjögren wrote:
Tom,
Don't you have the same readability problem with nested try/catch
blocks?
Yes, but I would really have them...

SqlConnection connection = null;
SqlCommand command = null;
DataSet ds = null;

try
{
// blah
}
catch
{
// blah
}
finally
{
if (ds != null) ds.Dispose ();
if (command != null) command.Dispose ();
if (connection != null) connection.Dispose ();
}

OK but then the code is no longer equivalent to what you get with
using blocks. If ds.Dispose() throws an exception the command and
connection will be left undisposed if you don't have the nesting.
Mattias


Good point...

--
Tom Shelton [MVP]

Nov 23 '05 #26
The Grim Reaper wrote:
Ever wish you'd just kept quiet about something?? :D


LOL! Not really. It's all a learning experience...

--
Tom Shelton [MVP]
Nov 23 '05 #27

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

Similar topics

8
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block?...
6
by: Tilfried Weissenberger | last post by:
Hi, I am a bit confused as to what the FINALLY block is meant for. What's the difference between: this.Cursor = Cursors.WaitCursor; try { //do some stuff } catch { //handle exception }...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
7
by: Sean Kirkpatrick | last post by:
I got caught with my pants down the other day when trying to explain Try...Catch...Finally and things didn't work as I had assumed. Perhaps someone can explain to me the purpose of Finally. I've...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
5
by: Morten Snedker | last post by:
The use of Try in the Finally part - is that overkill?. I think of the code failing before opening sqlCon - that would generate an error in the Finally part. How would Finally handle that? Try...
12
by: David Lozzi | last post by:
Howdy, I ran into a very interesting issue and I'm curios as to how this is suppose to work. I am using Try...Catch...Finally statements for all database connectivity in my ASP.NET 2.0 web...
9
by: GiJeet | last post by:
Hello, I come from the VB6 world where we'd put a single ON ERROR GOTO ErrHandler at the top of a method. Now whenever an error happened it would drop into the ErrHandler code. In .Net it seems...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.