check an exception and then continue process

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balasundarammca
    New Member
    • Dec 2008
    • 1

    check an exception and then continue process

    I want to check the Exception --- System.IO.Direc toryNotFoundExc eption
    If it occurs then i need to resume the process? Please Guide me Sir...
    Thanks....
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    Can you make use of a standard try - catch block?

    Format your code with the lines likely to throw an exception in the Try block, catch the exception and do nothing:

    Code:
    Try
        ' Do your work here
    Catch ex As System.IO.DirectoryNotFoundException
        ' Do nothing - resume process
    End Try
    Bear in mind that silently eating exceptions isn't considered to be good programming practice although there are some situations where it makes sense.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      Originally posted by nukefusion
      Bear in mind that silently eating exceptions isn't considered to be good programming practice although there are some situations where it makes sense.
      Keep Nukefusion's warning in mind. Gobbling up exceptions makes it difficult to debug your code later....it'll appear like your code is running fine but in actuality it's not functioning properly and you wont be able to tell what's happening.

      Comment

      • dminder
        New Member
        • Dec 2008
        • 2

        #4
        You would have to figure out how you want to handle the exception(s) then after you handle them, call the same sub/function again with the corrected info(parameters would probably be best).

        Good Luck!

        D

        Comment

        • MrMancunian
          Recognized Expert Contributor
          • Jul 2008
          • 569

          #5
          Of course, if you only catch a DirectoryNotFou ndException, you can just make a messagebox telling the user the directory wasn't found and then continue the process.

          I agree with Nukefusion and Frinny that you shouldn't ignore exceptions that are thrown at you, but in this particular case, I think it wouldn't hurt you.

          Steven
          Last edited by MrMancunian; Dec 29 '08, 05:03 PM. Reason: typo

          Comment

          Working...