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. Don't debug in try-catch block

Don't debug in try-catch block

Scheduled Pinned Locked Moved Visual Basic
debuggingquestion
11 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.
  • C cstrader232

    This didn't happen in vs2005 I don't think, but vs2008 throws exceptions in debug on errors within my try-catch blocks. Can I turn that off? Thanks

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

    That depends on which half of the Try/Catch the error occurs in. VS won't stop on an exception thrown inside a Try block. It WILL stop on an exception thrown in the Catch or Finally blocks.

    A guide to posting questions on CodeProject[^]
    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
         2006, 2007, 2008
    But no longer in 2009...

    C 1 Reply Last reply
    0
    • D Dave Kreskowiak

      That depends on which half of the Try/Catch the error occurs in. VS won't stop on an exception thrown inside a Try block. It WILL stop on an exception thrown in the Catch or Finally blocks.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      C Offline
      C Offline
      cstrader232
      wrote on last edited by
      #3

      Not so... my errors are being thrown within the try section. FI: Try Console.WriteLine(TTDG.Rows(1000).Cells(100).Value) Catch ex As Exception End Try

      N 1 Reply Last reply
      0
      • C cstrader232

        Not so... my errors are being thrown within the try section. FI: Try Console.WriteLine(TTDG.Rows(1000).Cells(100).Value) Catch ex As Exception End Try

        N Offline
        N Offline
        nlarson11
        wrote on last edited by
        #4

        If you have no code in your catch block then you will "eat"/ignore any error that occurs within the try. Been this way since at least 2003.

        'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

        C 1 Reply Last reply
        0
        • N nlarson11

          If you have no code in your catch block then you will "eat"/ignore any error that occurs within the try. Been this way since at least 2003.

          'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

          C Offline
          C Offline
          cstrader232
          wrote on last edited by
          #5

          All I can tell you is that it is definitely happening for me. No code in the catch, but the error is trapped in the try.

          N 1 Reply Last reply
          0
          • C cstrader232

            All I can tell you is that it is definitely happening for me. No code in the catch, but the error is trapped in the try.

            N Offline
            N Offline
            nlarson11
            wrote on last edited by
            #6

            ok but how many statements are you executing within the try. as soon as an exception occurs, you get kicked out of the try statements 4 and 5 below will not be executed if an exception occurs at statement 3 try exec 1 exec 2 exec 3 -> exception happens here exec 4 exec 5 catch end try

            'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

            C 1 Reply Last reply
            0
            • N nlarson11

              ok but how many statements are you executing within the try. as soon as an exception occurs, you get kicked out of the try statements 4 and 5 below will not be executed if an exception occurs at statement 3 try exec 1 exec 2 exec 3 -> exception happens here exec 4 exec 5 catch end try

              'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

              C Offline
              C Offline
              cstrader232
              wrote on last edited by
              #7

              What is the problem for me is that the exception within the try is thrown. The debugger stops and shows me the error. I thought that exceptions within the try would be ignored. Thanks

              L 1 Reply Last reply
              0
              • C cstrader232

                What is the problem for me is that the exception within the try is thrown. The debugger stops and shows me the error. I thought that exceptions within the try would be ignored. Thanks

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #8

                for anyone to answer this in any detail you should show the actual code (inside PRE tags!) AND the exact exception information. And you should have done this from the start, 3 hours ago. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                C 1 Reply Last reply
                0
                • L Luc Pattyn

                  for anyone to answer this in any detail you should show the actual code (inside PRE tags!) AND the exact exception information. And you should have done this from the start, 3 hours ago. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                  C Offline
                  C Offline
                  cstrader232
                  wrote on last edited by
                  #9

                  OK, here's one simple example

                  Sub test()
                  Dim x
                  Try
                  Console.WriteLine(x(0))
                  Catch ex As Exception

                      End Try
                  

                  end sub

                  Error thrown is: Object variable or With block variable not set.

                  L 1 Reply Last reply
                  0
                  • C cstrader232

                    OK, here's one simple example

                    Sub test()
                    Dim x
                    Try
                    Console.WriteLine(x(0))
                    Catch ex As Exception

                        End Try
                    

                    end sub

                    Error thrown is: Object variable or With block variable not set.

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #10

                    Using VB.NET 2008 Express, this

                    Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                        Dim x
                        Try
                            Console.WriteLine(x(0))
                        Catch exc As Exception
                            Console.WriteLine(Exc.ToString())
                        End Try
                    End Sub
                    

                    gives me 1. a compilation warning ("Variable 'x' is used before it has been assigned a value. A null reference exception could result at runtime."); you should not ignore warnings. 2. a run-time exception, which gets shown inside the catch block, as I would expect. ("System.NullReferenceException: Object variable or With block variable not set." + stack traceback) All looks normal to me. If yours behaves differently, there must be either a different setting (maybe under Tools/Options), although I wouldn't know which, or a general problem with your copy of VS. :)

                    Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                    I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                    C 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Using VB.NET 2008 Express, this

                      Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                          Dim x
                          Try
                              Console.WriteLine(x(0))
                          Catch exc As Exception
                              Console.WriteLine(Exc.ToString())
                          End Try
                      End Sub
                      

                      gives me 1. a compilation warning ("Variable 'x' is used before it has been assigned a value. A null reference exception could result at runtime."); you should not ignore warnings. 2. a run-time exception, which gets shown inside the catch block, as I would expect. ("System.NullReferenceException: Object variable or With block variable not set." + stack traceback) All looks normal to me. If yours behaves differently, there must be either a different setting (maybe under Tools/Options), although I wouldn't know which, or a general problem with your copy of VS. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


                      C Offline
                      C Offline
                      cstrader232
                      wrote on last edited by
                      #11

                      OK, thanks for your help! Happy holidays!

                      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