Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How can i send my cursor to catch even there is no error

How can i send my cursor to catch even there is no error

Scheduled Pinned Locked Moved Visual Basic
questioncomhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rprateek
    wrote on last edited by
    #1

    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

    R C 2 Replies Last reply
    0
    • R rprateek

      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

      R Offline
      R Offline
      rprateek
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • R rprateek

        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

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • R rprateek

          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

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          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 Sub

          Exceptions 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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups