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. Exceptions throw in try block

Exceptions throw in try block

Scheduled Pinned Locked Moved Visual Basic
questionannouncement
13 Posts 6 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

    OK, well for instance, this code throws a NullReferenceException and stops my processing

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

        End Try
    
    L Offline
    L Offline
    Luc Pattyn
    wrote on last edited by
    #4

    Do NOT create empty catch blocks; if you catch an exception, you should act on it, and either report it, or fix the situation, or both. Which line in the catch block do you want Visual Studio to highlight???????????????????????????????? :mad:

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


    Merry Christmas and a Happy New Year to all.


    C 1 Reply Last reply
    0
    • L Luc Pattyn

      Do NOT create empty catch blocks; if you catch an exception, you should act on it, and either report it, or fix the situation, or both. Which line in the catch block do you want Visual Studio to highlight???????????????????????????????? :mad:

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


      Merry Christmas and a Happy New Year to all.


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

      I think I am not explaining myself well. What is happening is that VS2008 is stopping execution on the error that is created within the try part of the try-catch block. My understanding (and my prior experience with VS2005) is that the debugger should ignore errors in this part of the block. ty

      L R 2 Replies Last reply
      0
      • C cstrader232

        I think I am not explaining myself well. What is happening is that VS2008 is stopping execution on the error that is created within the try part of the try-catch block. My understanding (and my prior experience with VS2005) is that the debugger should ignore errors in this part of the block. ty

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

        stop being stubborn, add a Console.WriteLine() or some other statement to the catch block, and try again. :~

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


        Merry Christmas and a Happy New Year to all.


        C 1 Reply Last reply
        0
        • L Luc Pattyn

          stop being stubborn, add a Console.WriteLine() or some other statement to the catch block, and try again. :~

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


          Merry Christmas and a Happy New Year to all.


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

          Doesn't matter... same thing.

          Dim x
          Try
          Console.WriteLine(x(0))
          Catch ex As Exception
          Console.WriteLine("Error")
          End Try

          L 1 Reply Last reply
          0
          • C cstrader232

            Doesn't matter... same thing.

            Dim x
            Try
            Console.WriteLine(x(0))
            Catch ex As Exception
            Console.WriteLine("Error")
            End Try

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

            asked and answered here[^]. :zzz:

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


            Merry Christmas and a Happy New Year to all.


            1 Reply Last reply
            0
            • C cstrader232

              OK, well for instance, this code throws a NullReferenceException and stops my processing

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

                  End Try
              
              N Offline
              N Offline
              nlarson11
              wrote on last edited by
              #9

              have you gone to menu tools/options/debugging/general and fooled with those settings?

              '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

                have you gone to menu tools/options/debugging/general and fooled with those settings?

                '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
                #10

                Yes, I've tried to change them all.

                N A 2 Replies Last reply
                0
                • C cstrader232

                  Yes, I've tried to change them all.

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

                  click on menu debug then click exceptions. i think you can define it there how you want it to behave. see if that's what your looking for.

                  '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

                  1 Reply Last reply
                  0
                  • C cstrader232

                    Yes, I've tried to change them all.

                    A Offline
                    A Offline
                    Alan N
                    wrote on last edited by
                    #12

                    Hi, So, specifically what is the debugger setting for the NullReferenceException? Your symptoms suggest that it is currently set to break when the exception is thrown. Alan.

                    1 Reply Last reply
                    0
                    • C cstrader232

                      I think I am not explaining myself well. What is happening is that VS2008 is stopping execution on the error that is created within the try part of the try-catch block. My understanding (and my prior experience with VS2005) is that the debugger should ignore errors in this part of the block. ty

                      R Offline
                      R Offline
                      Rick Shaub
                      wrote on last edited by
                      #13

                      cstrader232 wrote:

                      My understanding (and my prior experience with VS2005) is that the debugger should ignore errors in this part of the block.

                      Your understanding is wrong. When an exception occurs, it is "thrown" upward through the call stack until a catch is encountered or the top of the stack is reached. If you want to have code that runs no matter what you can put it in a Finally block. Or, since this is the VB section, you can use the horrific "On Error Resume Next" construct.

                      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