How can i send my cursor to catch even there is no error
-
I want to send my cursor to catch in try / catch block when one of my condition doesn't meet how can i acheive that ? Please look into the following code that explains a bit: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer i = Val(Me.txtErrMsg.Text) Try If i = 4 Then ' If i = 4 then I want to go to catch and display the message Now throwing exception Else Me.txtErrMsg.Text = "Normal" End If Catch ex As Exception Me.txtErrMsg.Text = "Now throwing Exception" End Try End Sub When i = 4 then I want to go to catch and show the message how can I do that ?? Thanks in advance
Blog for Programmers http://www.rprateek.blogspot.com
-
I want to send my cursor to catch in try / catch block when one of my condition doesn't meet how can i acheive that ? Please look into the following code that explains a bit: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer i = Val(Me.txtErrMsg.Text) Try If i = 4 Then ' If i = 4 then I want to go to catch and display the message Now throwing exception Else Me.txtErrMsg.Text = "Normal" End If Catch ex As Exception Me.txtErrMsg.Text = "Now throwing Exception" End Try End Sub When i = 4 then I want to go to catch and show the message how can I do that ?? Thanks in advance
Blog for Programmers http://www.rprateek.blogspot.com
I found the answers guys if you wanna know... goto following link: http://rprateek.blogspot.com/2008/08/how-can-we-send-cursor-to-catch-even-if.html[^]
Blog for Programmers http://www.rprateek.blogspot.com
-
I found the answers guys if you wanna know... goto following link: http://rprateek.blogspot.com/2008/08/how-can-we-send-cursor-to-catch-even-if.html[^]
Blog for Programmers http://www.rprateek.blogspot.com
That isn't actually a good answer. You are using the exception handling system to modify regular program flow rather than respond to exceptional events. Exceptions are very expensive to handle and should not be used unless the thing throwing the exception is a very unusual case that you don't expect to happen, but need to handle if it does. You also say in your blog post that "in the catch part you can do all your garbage collection and closing the instances." That is a very bad idea. It means you have to write the code twice, once for the good cases where everything works, and once for the bad cases, where things don't work out. What you should be really doing is creating a Finally block so that the resrouces get cleaned up regardless of whether the method ended well, or not.
Recent blog posts: *SQL Server / Visual Studio install order *Installing SQL Server 2005 on Vista *Crazy Extension Methods Redux My Blog
-
I want to send my cursor to catch in try / catch block when one of my condition doesn't meet how can i acheive that ? Please look into the following code that explains a bit: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer i = Val(Me.txtErrMsg.Text) Try If i = 4 Then ' If i = 4 then I want to go to catch and display the message Now throwing exception Else Me.txtErrMsg.Text = "Normal" End If Catch ex As Exception Me.txtErrMsg.Text = "Now throwing Exception" End Try End Sub When i = 4 then I want to go to catch and show the message how can I do that ?? Thanks in advance
Blog for Programmers http://www.rprateek.blogspot.com
Your code would be better written as:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
i = Val(Me.txtErrMsg.Text)
If i = 4 Then
Me.txtErrMsg.Text = "Now throwing Exception"
Else
Me.txtErrMsg.Text = "Normal"
End If
End SubExceptions are expensive. They take many clock cycles as the runtime has to figure out how to back out of what ever it was doing.
Recent blog posts: *SQL Server / Visual Studio install order *Installing SQL Server 2005 on Vista *Crazy Extension Methods Redux My Blog