| 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 |