Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2007, 02:59 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default Try catch exception

Hi All
I am working on someone else code and beginner as well
Just trying to understand why use
On Error GoTo err statements in VB.NET although we have try catch available is there any logic

Is there any chart to understand OleDb.OleDbConnection
which shows all methods of this class in nice ways

Thanks
Ayaz


 
Old May 10th, 2007, 06:37 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Here is a link to all Class Members of the OleDb.OleDbConnection class:
http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbconnection_members(VS.71).a spx

In so far as On Error Goto, I personally despise that type of error handling as GoTo statements can make code difficult to debug. I would suggest using Try Catch over Goto.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 10th, 2007, 07:34 AM
Friend of Wrox
 
Join Date: Apr 2007
Posts: 110
Thanks: 1
Thanked 2 Times in 2 Posts
Send a message via MSN to ayazhoda
Default

Thanks for reply

I've question here again let suppose we have condition here

try
   'do somthing
catch
   'catch error
finally
    ' run this

In this above try catch process stops when it catch error
is it possible to do like

catch error if there is but dont stop process and in the end you put all error in one string which mean if we have any error in FOR loop but for loop must not stop if finds any error pass it to exception and move to next record

I hope this is not very complicated

Regards

Ayaz

 
Old May 10th, 2007, 07:53 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well, you have 2 choices.

Choice A: Use structured error handling (Try Catch Finally) but, for what you are wanting to do, this could become cumbersome.

You would have to do something like this

Try
  'Line of code
Catch
End Try

Try
  'Line of code
Catch
End Try

Try
  'Line of code
Catch
End Try

So you would have to place each line of code inside its own Try Catch to continue execution of your application.

Choice B: You can use unstructured error handling :shudder:

Private Sub foo()
On Error Resume Next

End Sub

This will cause any exceptions that are thrown to be sliently handled and the execution of your code will continue on.

You can use one or the other, but you can NOT mix and match them so be aware of that. For more information read this:
http://msdn2.microsoft.com/en-us/library/aa289505(VS.71).aspx

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 10th, 2007, 10:27 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Myself, I really love On Error GoTo . . .

One reason is the case that you have brought up, where you might need to stay at the location you are currently at, while handling errors.

An example is trying to open a file that might be in use, but that is used really breifly every time it is used. In this case, I put a counter and a short time delay in the error handler. I try to open the file in a loop that ends when the file is opened. If the attempt raises an error, I am sent to the error handler. There I increment my counter, wait a few milliseconds, then Resume Next (which then procedes with the loop).
If I arrive at the error handler with the variable having been incremented too many times, I presume I am never going to get access to the file, and I handle it as a true error.

One of the reasons I don't like Try / Catch much is the amount of code-window real estate the block takes up. (Not a really technical issue; personal preference.)

I know a lot of people hate On Error GoTo—and maybe I'll be one of them some day—but I'm not one of them yet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
throw an exception in catch Muyavil Java Basics 3 April 11th, 2009 10:56 PM
Try...Catch lowell VB.NET 3 July 23rd, 2007 06:35 AM
Try and Catch? mujju PHP How-To 2 January 20th, 2005 12:27 PM
Catch Problem dag VB.NET 2002/2003 Basics 1 December 8th, 2003 09:28 PM
How to catch error. lancet2003 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 December 3rd, 2003 02:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.