error handle

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

    #1

    error handle

    Hey Guys!

    I am moving from vb6 to vb2005

    I was using:

    on error go lbl_error:

    code..
    code..

    exit sub or function
    lbl_error:
    .code
    code
    but it vb 2005 we have
    try.. catch.. finally end try.

    In your opinion wich is better for performance and code reading ?

    Daniel




  • iwdu15

    #2
    RE: error handle

    im assuming try catch is better. i was always taught to NEVER EVER use "goto"
    and always use try catch end try....i dont have any evidence but i do kno
    that the try catch makes the code so much easier to read
    --
    -iwdu15

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: error handle

      "iwdu15" <jmmgoalsteraty ahoodotcom> schrieb:[color=blue]
      > i dont have any evidence but i do kno
      > that the try catch makes the code so much easier to read[/color]

      Really?

      \\\
      On Error Resume Next
      Foo()
      Goo()
      Boo()
      ///

      - versus -

      \\\
      Try
      Foo()
      Catch
      End Try
      Try
      Goo()
      Catch
      End Try
      Try
      Boo()
      Catch
      End Try
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: error handle

        Herfried,

        You want to show with your example that for reading the try, catch, finally,
        end try is better.

        Or are you somebody who has in his programs really something like this.[color=blue]
        > \\\
        > On Error Resume Next
        > Foo()
        > Goo()
        > Boo()
        > ///[/color]

        Without any sentence acting on that between those rows?

        Cor

        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
        news:Oa$kwjEgGH A.2032@TK2MSFTN GP02.phx.gbl...[color=blue]
        > "iwdu15" <jmmgoalsteraty ahoodotcom> schrieb:[color=green]
        >> i dont have any evidence but i do kno that the try catch makes the code
        >> so much easier to read[/color]
        >
        > Really?
        >
        > \\\
        > On Error Resume Next
        > Foo()
        > Goo()
        > Boo()
        > ///
        >
        > - versus -
        >
        > \\\
        > Try
        > Foo()
        > Catch
        > End Try
        > Try
        > Goo()
        > Catch
        > End Try
        > Try
        > Boo()
        > Catch
        > End Try
        > ///
        >
        > --
        > M S Herfried K. Wagner
        > M V P <URL:http://dotnet.mvps.org/>
        > V B <URL:http://classicvb.org/petition/>[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: error handle

          "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb:[color=blue]
          > You want to show with your example that for reading the try, catch,
          > finally, end try is better.[/color]

          I wanted to demonstrate that there are some situations in which 'On Error
          Resume Next' is superior over 'Try...Catch' because it doesn't blow up the
          code.
          [color=blue]
          > Or are you somebody who has in his programs really something like this.[color=green]
          >> \\\
          >> On Error Resume Next
          >> Foo()
          >> Goo()
          >> Boo()
          >> ///[/color]
          >
          > Without any sentence acting on that between those rows?[/color]

          It simply depends on the exact case. The problem I am experiencing with
          'Try...Catch' is that it doesn't support resuming without placing every
          statement in a separate 'Try...Catch' block. My conclusion is that both
          solutions, 'On Error Resume Next' and 'Try...Catch' should be brought
          together by allowing 'Try Resume' blocks or similar and allow the 'Resume'
          command inside the exception handler's 'Catch' block:

          \\\
          Try
          Call1()
          Call2()
          Call3()
          Catch
          If ... Then
          Resume
          End If
          End Try
          ///

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: error handle

            Herfried,

            [color=blue]
            >Resume' blocks or similar and allow the 'Resume' command inside the
            >exception handler's 'Catch' block:
            >[/color]

            Developers my age have maybe a fobie from the Cobol "Alter" statement and
            those like that, but we never want anything that looks like that again.


            Cor


            Comment

            • Jay B. Harlow [MVP - Outlook]

              #7
              Re: error handle

              Herfried,
              You can partially do that today.

              | \\\
              | Try
              | Call1()

              Resume:

              | Call2()
              | Call3()
              | Catch
              | If ... Then

              Goto Resume

              | End If
              | End Try
              | ///

              Unfortunately you need an explicit label & know which label to goto, which
              is why I say *partially* do it today.

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


              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
              news:%23XnCmhLg GHA.4940@TK2MSF TNGP05.phx.gbl. ..
              | "Cor Ligthert [MVP]" <notmyfirstname @planet.nl> schrieb:
              | > You want to show with your example that for reading the try, catch,
              | > finally, end try is better.
              |
              | I wanted to demonstrate that there are some situations in which 'On Error
              | Resume Next' is superior over 'Try...Catch' because it doesn't blow up the
              | code.
              |
              | > Or are you somebody who has in his programs really something like this.
              | >> \\\
              | >> On Error Resume Next
              | >> Foo()
              | >> Goo()
              | >> Boo()
              | >> ///
              | >
              | > Without any sentence acting on that between those rows?
              |
              | It simply depends on the exact case. The problem I am experiencing with
              | 'Try...Catch' is that it doesn't support resuming without placing every
              | statement in a separate 'Try...Catch' block. My conclusion is that both
              | solutions, 'On Error Resume Next' and 'Try...Catch' should be brought
              | together by allowing 'Try Resume' blocks or similar and allow the 'Resume'
              | command inside the exception handler's 'Catch' block:
              |
              | \\\
              | Try
              | Call1()
              | Call2()
              | Call3()
              | Catch
              | If ... Then
              | Resume
              | End If
              | End Try
              | ///
              |
              | --
              | M S Herfried K. Wagner
              | M V P <URL:http://dotnet.mvps.org/>
              | V B <URL:http://classicvb.org/petition/>
              |


              Comment

              Working...