Resuming Try

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Resuming Try

    Hi

    I have several statements in my try block. After catching an exception and
    dealing with it in catch section, is there a way to resume from next
    statement in try section kinda like resume next in vb?

    Thanks

    Regards


  • Armin Zingler

    #2
    Re: Resuming Try

    "John" <info@nospam.in fovis.co.ukschr ieb
    Hi
    >
    I have several statements in my try block. After catching an
    exception and dealing with it in catch section, is there a way to
    resume from next statement in try section kinda like resume next in
    vb?
    No. You'd have to put each single statement in a try-catch block - or
    still use on error resume next.


    Armin

    Comment

    • kimiraikkonen

      #3
      Re: Resuming Try

      On Apr 28, 10:38 pm, "John" <i...@nospam.in fovis.co.ukwrot e:
      Hi
      >
      I have several statements in my try block. After catching an exception and
      dealing with it in catch section, is there a way to resume from next
      statement in try section kinda like resume next in vb?
      >
      Thanks
      >
      Regards
      John,
      You can use seperate try-catch exception handlers for each statements
      alternatively.

      Onur

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Resuming Try

        John,
        Yes, use a Goto statement.

        Try
        TryAgain1:
        Something()
        TryAgain2:
        SomethingElse()
        Catch
        If whatever Then
        Goto TryAgain1
        Else
        Goto TryAgain2
        End If
        End Try

        Of course some people feel Goto is evil & should be avoided at all costs; I
        view the above more of a "Resume Try" rather then a Goto statement. There
        are three simple rules for Goto in a Catch block.

        - A Goto can only branch from a Catch statement into the Try block of the
        same statement
        - A Goto can never branch out of a Finally statement
        - A Goto can never branch into a Catch or Finally statement

        --
        Hope this helps
        Jay B. Harlow [MVP - Outlook]
        ..NET Application Architect, Enthusiast, & Evangelist
        T.S. Bradley - http://www.tsbradley.net


        "John" <info@nospam.in fovis.co.ukwrot e in message
        news:OK2NgdWqIH A.4928@TK2MSFTN GP04.phx.gbl...
        Hi
        >
        I have several statements in my try block. After catching an exception and
        dealing with it in catch section, is there a way to resume from next
        statement in try section kinda like resume next in vb?
        >
        Thanks
        >
        Regards
        >

        Comment

        • Bill McCarthy

          #5
          Re: Resuming Try


          "John" <info@nospam.in fovis.co.ukwrot e in message
          news:OK2NgdWqIH A.4928@TK2MSFTN GP04.phx.gbl...
          Hi
          >
          I have several statements in my try block. After catching an exception and
          dealing with it in catch section, is there a way to resume from next
          statement in try section kinda like resume next in vb?
          >
          If you want Resume Next then either use the solution Jay showed of using
          GoTo from inside the Catch, or you can in fact use On Error Resume Next as
          per Visual Basic 6 style of coding and the compiler does that GoTo and
          labels for you, but you cannot mix and match that. Personally, I'd do
          neither, instead I'd look at refactorign the code out that can cause errors
          that you wish to still resume next from, and change that into logical
          checking, such as checking for a condition, or a null returned from a method
          etc, and also consider multiple small Try Catch blocks.

          Comment

          Working...