Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

try-catch .vs. "on error"

Status
Not open for further replies.

tg2003

IS-IT--Management
Feb 6, 2003
270
IL
Hi,

I'm a VB.NET rookie, but a VB6 veteran.

I would like to ask you what is considered better in VB.NET.

I would like to catch run-time errors.

In VB6 I use "on error resume next / goto ..."

I see that in VB.NET I have the try-catch, just like C++ and Java.

What's better? pros and cons?

Thanks in advance!
 
Try-Catch is far better than On Error-Goto. For one thing, you can use Finally after Try-Catch to clean up after an error or successful completion of the code block.

Try
'do some stuff
Catch
'handle errors
Finally
'clean up
End Try



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
jebenson has it right. I've been using VB.Net for 6 six years and have never used On Error GoTo in .Net. Rarely do I used GoTo at all.
 
On Error Resume Next", "On Error goto 0", "On Error goto -1" and "On Error Goto [label]" are still supported at least in .Net 1.1.

In some cases where a line of code is optional, on error resume next may be faster that the whole try catch logic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top