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

'finally' block

Is it possible to have more than one try/catch/finally
block within a method? Also, if the code never enters the
try block of code, is the finally block executed? I have
a try block in a branch of a switch statement and I only
want the finally to execute if the branch of the switch
statement is executed.
Nov 15 '05 #1
3 4805
Yes you can have multiple t/c/f blocks in one method.
The finally will not be executed if you return before your
try or condition around it. As for your switch logic, I'd have to see
the code, there are differnet possibilities

JIM

"Brian" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Is it possible to have more than one try/catch/finally
block within a method? Also, if the code never enters the
try block of code, is the finally block executed? I have
a try block in a branch of a switch statement and I only
want the finally to execute if the branch of the switch
statement is executed.

Nov 15 '05 #2
you can have as many try/catch/finally block in a method
as you like. The finally block only executes when the
corresponding try block was executed.

Tu-Thach
-----Original Message-----
Is it possible to have more than one try/catch/finally
block within a method? Also, if the code never enters thetry block of code, is the finally block executed? I have
a try block in a branch of a switch statement and I only
want the finally to execute if the branch of the switch
statement is executed.
.

Nov 15 '05 #3
you can have

try
{
.......
.......
}
catch(C1)
{
......
}
catch(C2)
{
.......
}
finally
{
}

yes you can have the entire block within a switch brach... but then make
sure the catch if you include any and the finally if you add that as well
are within the same branch
if you want a global try catch finally
try placing calling method within try block and catch the exception and your
finally block

try
{
callFuncitonWithSwitch()
}
catch(c1)
{
}
catch(c2)
{
}
finally
{
}

the finally block should be associated with a corresponding try block... so
you cant have a try at one place and finally at a totally irrelevant
place...
and finally if the code execution never enters try... it never goes through
the finally either...

--
Regards,

HD

"Brian" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
Is it possible to have more than one try/catch/finally
block within a method? Also, if the code never enters the
try block of code, is the finally block executed? I have
a try block in a branch of a switch statement and I only
want the finally to execute if the branch of the switch
statement is executed.

Nov 15 '05 #4

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

Similar topics

2
by: cottonviking | last post by:
Greetings, all! I've been pondering the pitfalls of aborting a secondary thread in a service app I'm writing (VB, fx v1.1). Everything I've read so far pretty much dissuades one from aborting one...
16
by: Bill | last post by:
Say I have a childThread currently is running a finally block to cleanup external resources. At the same time the main thread calls childThread.Abort(). The question is: when the...
1
by: | last post by:
After finally block executes, the control goes back to the caller..I was expecting the control to go to the next statement after the finally block. Thanks for your input.
7
by: George | last post by:
Hi, Once the execution enters the "finally" block, the execution could have followed 1. normal/non-exception execution. (I guess everyone knows what I mean here.) 2. Exception was thrown,...
9
by: TC | last post by:
Hey All, I posted this to the Crypto users group and forgot to add the VB.Net users group. I apologize for any confusion. I have been testing a try / catch / finally block and purposely...
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: 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
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
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...

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.