Go Back   Forum Care Forums > Development Reference Area > Visual Basic

Reply
 
LinkBack Thread Tools Display Modes
PART II : VB.NET Why doesn't FINALLY execute
Old
  (#1)
Raymond Lesher
Guest
 
Posts: n/a
Default PART II : VB.NET Why doesn't FINALLY execute - 06-04-2007, 09:46 AM

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
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: PART II : VB.NET Why doesn't FINALLY execute
Old
  (#2)
Raymond Lesher
Guest
 
Posts: n/a
Default Re: PART II : VB.NET Why doesn't FINALLY execute - 06-04-2007, 09:46 AM

Sorry, please ignore my post. I'll remove it shortly.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: PART II : VB.NET Why doesn't FINALLY execute
Old
  (#3)
M. Posseth
Guest
 
Posts: n/a
Default Re: PART II : VB.NET Why doesn't FINALLY execute - 06-04-2007, 09:46 AM


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" <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED 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



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: PART II : VB.NET Why doesn't FINALLY execute
Old
  (#4)
Raymond Lesher
Guest
 
Posts: n/a
Default Re: PART II : VB.NET Why doesn't FINALLY execute - 06-04-2007, 09:46 AM

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" <EMAIL REMOVED> wrote in message news:<cfthi4$79t$EMAIL REMOVED>...
> 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" <EMAIL REMOVED> wrote in message
> news:EMAIL REMOVED 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

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top