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

What's the difference?


void functionA() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
} finally {
doThingC();
}
}

void functionB() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
}
doThingC();
}

Do the above two methods behave differently or do they do the exact same
thing?

TIA
Jul 17 '05 #1
3 1570
Daniel T. wrote:
void functionA() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
} finally {
doThingC();
}
}

void functionB() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
}
doThingC();
}

Do the above two methods behave differently or do they do the exact same
thing?

TIA


The difference is this:
The statments under the body finally will always be executed, even when
an exception has been catched; thus when an Exception e has been
catched, functionA shall do doThingC, functionB won't.
At least that's what I learned at school.
grtz
Jul 17 '05 #2
If exception is thrown in doThingB(), functionA will call doThingC() and
functionB will not.

Boris Cinkler

"Daniel T." <po********@earthlink.net> wrote in message
news:po******************************@news1.east.e arthlink.net...

void functionA() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
} finally {
doThingC();
}
}

void functionB() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
}
doThingC();
}

Do the above two methods behave differently or do they do the exact same
thing?

TIA

Jul 17 '05 #3
Wouter wrote:
Daniel T. wrote:
void functionA() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
} finally {
doThingC();
}
}

void functionB() {
try {
doThingA();
} catch ( Exception e ) {
doThingB();
}
doThingC();
}

Do the above two methods behave differently or do they do the exact
same thing?

TIA

The difference is this:
The statments under the body finally will always be executed, even when
an exception has been catched; thus when an Exception e has been
catched, functionA shall do doThingC, functionB won't.
At least that's what I learned at school.


This is incorrect. If functionB() enters the catch block do to an
exception being thrown, it will still execute doThingC() unless
doThingB() throws an exception. Another differentiating situation is if
doThingA() throws a Throwable that is not an Exception (very unlikely
and poor programming practice).

The simple way to think about this is like so. The finally block is
always executed, even if the result of the function is to throw an
exception. Thus it is a good idea to release resources in finally
blocks, e.g. database connections, etc.

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #4

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
1
by: mike | last post by:
best regards: What is the difference between DOM Level 1 and DOM Level 2. Thank you. May god be with you.
5
by: radnus2004 | last post by:
Hi all, I am not clear what is the difference between signed and unsigned in C. Many say, unsigned means only +ve values and 0. Can I use unsigned int i = -3? What happens internally ? What...
10
by: tinesan | last post by:
Hello fellow C programmers, I'm just learning to program with C, and I'm wondering what the difference between signed and unsigned char is. To me there seems to be no difference, and the...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
12
by: Nathan Sokalski | last post by:
What is the difference between the Page_Init and Page_Load events? When I was debugging my code, they both seemed to get triggered on every postback. I am assuming that there is some difference,...
3
by: Anoj Kumar | last post by:
Hi All , can anyone tell me what is the difference between the following declaration and how it affects application performance. 1. Dim cn As ADODB.Connection Set cn = New ADODB.Connection
6
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. What is the difference between a Field and a Property? Here is the context. In the VS.NET 2002 documentation, in the "String Members" section, we have the...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
49
by: Zach | last post by:
After having taken a looong break from VB (last used 6.0), I started getting back into programming again, this time with VS 2005. I began reading up on VB.NET from various sources (books,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.