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

what is the point of 'Finally'

I've been looking at some code and started wondering what is the point of
'Finally" in Try Catch Finally.
Why not just place the Finally code after the End Try? Will the Catch fire
if there is an error in Finally?

Try
Dosomething()

Catch ex as Exception
messagebox.show(ex.message)

Finally
CompleteProcess()

End Try

---------------------------------

Try
Dosomething()

Catch ex as exception
messagebox.show(ex.message)

End Try

CompleteProcess()

----------------------------------

What's the difference?

Thanks,
m
Dec 23 '05 #1
2 1179
This has been asked many times before.

If the try or catch block is going to have a Return statement, then you
would have to place duplicate code in both the Try and Catch to execute
right before the Return. And if the Try has multiple return statements, you
would have to copy that code right before each one.

Additionally, you may not have a Catch block at all. But you may want code
to execute regardless of whether or not the Try block completed
successfully. So you can put that in the Finally, and not have any Catch
blocks at all.

"Mike W" <th********@yahoo.com> wrote in message
news:Vo****************@tornado.texas.rr.com...
I've been looking at some code and started wondering what is the point of
'Finally" in Try Catch Finally.
Why not just place the Finally code after the End Try? Will the Catch
fire if there is an error in Finally?

Try
Dosomething()

Catch ex as Exception
messagebox.show(ex.message)

Finally
CompleteProcess()

End Try

---------------------------------

Try
Dosomething()

Catch ex as exception
messagebox.show(ex.message)

End Try

CompleteProcess()

----------------------------------

What's the difference?

Thanks,
m

Dec 23 '05 #2
"Mike W" <th********@yahoo.com> schrieb:
I've been looking at some code and started wondering what is the point of
'Finally" in Try Catch Finally.
Why not just place the Finally code after the End Try? Will the Catch
fire if there is an error in Finally?


There has been a discussion about this topic on this group recently:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/0c8467475e2bcafb/d5ea0be99e897adb>

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

Dec 23 '05 #3

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?...
24
by: Dave | last post by:
Maybe I'm missing something here, but I can't see the purpose of the 'finally' keyword. What is the difference between: try { doSomething() } catch { handleError(); }
6
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?...
2
by: Carl Johansson | last post by:
Except for the syntax, what is the difference, if any, between this... /* ---------------------------------------------------------------------- */ private void Form1_Paint(object sender,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.