Home All Groups Group Topic Archive Search About
Author
25 May 2006 8:38 PM
Brahm
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

Author
25 May 2006 8:56 PM
iwdu15
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
Author
25 May 2006 10:16 PM
Herfried K. Wagner [MVP]
"iwdu15" <jmmgoalsteratyahoodotcom> schrieb:
> i dont have any evidence but i do kno
> that the try catch makes the code so much easier to read

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/>
Author
26 May 2006 7:34 AM
Cor Ligthert [MVP]
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.
> \\\
> On Error Resume Next
> Foo()
> Goo()
> Boo()
> ///

Without any sentence acting on that between those rows?

Cor

Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schreef in bericht
news:Oa$kwjEgGHA.2032@TK2MSFTNGP02.phx.gbl...
> "iwdu15" <jmmgoalsteratyahoodotcom> schrieb:
>> i dont have any evidence but i do kno that the try catch makes the code
>> so much easier to read
>
> 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/>
Author
26 May 2006 11:34 AM
Herfried K. Wagner [MVP]
"Cor Ligthert [MVP]" <notmyfirstn***@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/>
Author
26 May 2006 11:59 AM
Cor Ligthert [MVP]
Herfried,


>Resume' blocks or similar and allow the 'Resume' command inside the
>exception handler's 'Catch' block:
>

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
Author
26 May 2006 12:19 PM
Jay B. Harlow [MVP - Outlook]
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


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:%23XnCmhLgGHA.4940@TK2MSFTNGP05.phx.gbl...
| "Cor Ligthert [MVP]" <notmyfirstn***@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/>
|