error handle

  • Thread starter Thread starter Brahm
  • Start date Start date
B

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
 
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 said:
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
///
 
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
 
Cor Ligthert said:
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.

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
///
 
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
 
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


| > 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/>
|
 
Back
Top