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. Error Handling

Error Handling

Scheduled Pinned Locked Moved Visual Basic
helpquestion
7 Posts 4 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.
  • D Offline
    D Offline
    dpagka
    wrote on last edited by
    #1

    I want to prevet users from errors Should I use "On Error goto" statement or "Try catch end try" block. Although i dont want my program to rum slower due to error handling. Do you know which method is faster? Thanks in advance

    C D 2 Replies Last reply
    0
    • D dpagka

      I want to prevet users from errors Should I use "On Error goto" statement or "Try catch end try" block. Although i dont want my program to rum slower due to error handling. Do you know which method is faster? Thanks in advance

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

      Use Try/Catch dpagka wrote: Do you know which method is faster? The more important thing is that you use it correctly. It won't matter how fast one is over the other if it takes you a week to fix a bug because On Error Goto is so contrived and you introduce 2 new bugs at the same time.


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      1 Reply Last reply
      0
      • D dpagka

        I want to prevet users from errors Should I use "On Error goto" statement or "Try catch end try" block. Although i dont want my program to rum slower due to error handling. Do you know which method is faster? Thanks in advance

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Try/Catch blocks are very much the better way to go. Error handling doesn't add a huge overhead to your code, so I don't know why that's a concern... If your code errors out, Error Handling definately wins the speed competition, because if you don't the error, your code comes to a screeching halt. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        T 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Try/Catch blocks are very much the better way to go. Error handling doesn't add a huge overhead to your code, so I don't know why that's a concern... If your code errors out, Error Handling definately wins the speed competition, because if you don't the error, your code comes to a screeching halt. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          sure, but you cannot apply any Resume... (even if - i aggree - gotos are quite bad to use...


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          D 1 Reply Last reply
          0
          • T toxcct

            sure, but you cannot apply any Resume... (even if - i aggree - gotos are quite bad to use...


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            :confused::confused::confused::confused: If your code is written correctly, why on earth would you need to? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            T 1 Reply Last reply
            0
            • D Dave Kreskowiak

              :confused::confused::confused::confused: If your code is written correctly, why on earth would you need to? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              while programming in console mode, this becomes very useful when getting a bad user input and want to get it again until the user type its value correctly... this can't be done with exceptions (try and catch blocks) except if you use explicit gotos, that behavies the same...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              D 1 Reply Last reply
              0
              • T toxcct

                while programming in console mode, this becomes very useful when getting a bad user input and want to get it again until the user type its value correctly... this can't be done with exceptions (try and catch blocks) except if you use explicit gotos, that behavies the same...


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                Wanna bet?! Just a little something off the top of my head...

                Dim validInput As Boolean = False
                Dim choice As Integer
                Do
                Try
                choice = Console.ReadLine()
                ...Whatever else you need...
                If choice is valid Then
                validInput = True
                End If
                Catch ex As Exception
                ...Whatever you want here...
                End Try
                Loop While Not validInput

                RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                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