473,325 Members | 2,816 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,325 software developers and data experts.

PART II : VB.NET Why doesn't FINALLY execute

Oops! Forgot a line of code!!!!! Sorry. This code example should
display my problem properly.

Why does the finally clause in the Test method (below) NOT execute in
my "foo" example, but DOES execute in my "bar" example?
'Test-Finally does NOT execute
Private Sub foo()
Test()
End Sub

'Test-Finally DOES execute
Private Sub bar()
Try
Test()
Catch ex As Exception

End Try
End Sub

Private Sub Test()

Dim x As Double

Try
x = 1 / 0

Catch ex As Exception
Console.WriteLine("Exception Block")
Throw ex

Finally
Console.WriteLine("Finally Block")

End Try

End Sub
Jul 17 '05 #1
3 3198
Sorry, please ignore my post. I'll remove it shortly.
Jul 17 '05 #2

Well i just pasted this code in my dev environment ( VS.NET 2003
Enterprise ) and it does execute in bot both situations

so ..... ???????
Happy coding

M. Posseth [MCP]
"Raymond Lesher" <rl****@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Oops! Forgot a line of code!!!!! Sorry. This code example should
display my problem properly.

Why does the finally clause in the Test method (below) NOT execute in
my "foo" example, but DOES execute in my "bar" example?
'Test-Finally does NOT execute
Private Sub foo()
Test()
End Sub

'Test-Finally DOES execute
Private Sub bar()
Try
Test()
Catch ex As Exception

End Try
End Sub

Private Sub Test()

Dim x As Double

Try
x = 1 / 0

Catch ex As Exception
Console.WriteLine("Exception Block")
Throw ex

Finally
Console.WriteLine("Finally Block")

End Try

End Sub

Jul 17 '05 #3
Yeah, that was my mistake. Long story short, I was under the
impression that 1/0 generated an error in vb.net like it does in c#,
but it doesn't. I tested the code sample via c# not vb.net. My
mistake.

My goal is to raise an error in the try. In this case, a better
example would have been "throw new system.exception" instead of "x = 1
/ 0".

Under the hopefully guarenteed error being raised I then run into the
finally not be executed in both situations.

Thank you for responding.

-Ray

"M. Posseth" <mi*****@nohausystems.nl> wrote in message news:<cf**********@reader13.wxs.nl>...
Well i just pasted this code in my dev environment ( VS.NET 2003
Enterprise ) and it does execute in bot both situations

so ..... ???????
Happy coding

M. Posseth [MCP]
"Raymond Lesher" <rl****@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Oops! Forgot a line of code!!!!! Sorry. This code example should
display my problem properly.

Why does the finally clause in the Test method (below) NOT execute in
my "foo" example, but DOES execute in my "bar" example?
'Test-Finally does NOT execute
Private Sub foo()
Test()
End Sub

'Test-Finally DOES execute
Private Sub bar()
Try
Test()
Catch ex As Exception

End Try
End Sub

Private Sub Test()

Dim x As Double

Try
x = 1 / 0

Catch ex As Exception
Console.WriteLine("Exception Block")
Throw ex

Finally
Console.WriteLine("Finally Block")

End Try

End Sub

Jul 17 '05 #4

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

Similar topics

1
by: Raymond Lesher | last post by:
Why does the finally clause in the Test method (below) NOT execute in my "foo" example, but DOES execute in my "bar" example? 'Test-Finally does NOT execute Private Sub foo() Test() End Sub...
53
by: Alf P. Steinbach | last post by:
So, I got the itch to write something more... I apologize for not doing more on the attempted "Correct C++ Tutorial" earlier, but there were reasons. This is an UNFINISHED and RAW document,...
16
by: Ken | last post by:
What is the purpose of a finally block in try-catch- finally? I am confused because, if I am reading the definition correctly, this block seems unnecessary. Consider the following from the Visual...
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?...
17
by: Alexander Mueller | last post by:
I have always wondered what finally is actually for. What would be the exact difference between try { somecode1(); } catch(Exception) { somecode2();
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...
6
by: homevista | last post by:
PART III: Putting things together In part I we examined the modem to verify that it supported voice. If so, we took a note about the voice data format that we would use. In the second part, we...
1
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts...
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...
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...
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)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.