Solved

When to use Try...Catch

Posted on 2001-09-17
6
176 Views
Last Modified: 2010-05-02
I guess this is more of a general programming question than a VB question, but maybe someone can give me an answer.

When is it appropriate to use Try...Catch statements?  Should I put them around every line of code in my application, or only use them in certain instances?  Do they effect performance?  Are there any general guidelines?

Thanks!
0
Comment
Question by:NJordan72
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 15 total points
ID: 6488042
Try...Catch...Finally... is used for the purpose of "Exception" handling - which is the more general case of what is generally refered to as Error Handling.

Try...Catch... is generally used to "protect" blocks of code where you "expect" or "anticipate" that errors (exceptions to normal execution) might occur.  If an exception DIOES occur in the Try block, the code will immediately jump to the "Catch" block, where you would typically provide code to "handle" the exception.

The General mechanisms for Exception hadling, when to do it, and how to do it, is one of the major areas of learning hw to be an effective programmer.  THis topic IDS NOT one which can be easily explained in a restricted forum such as this.  Generally, to become adept at handling errors (exception) may in fact require several years of Programming experience.
0
 
LVL 3

Expert Comment

by:Joebob
ID: 6488100
The Visual C++ area would be a better place to post this question.  Visual Basic does not support Try Catch Finally blocks, it only supports On Error Goto/Resume statements.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6488105
I took the question as refering to VB.NET --which DOES suport Try..CAtch..Finally...
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 3

Expert Comment

by:Joebob
ID: 6488154
True, I seldom think about .Net since it will be in beta for many months to come.
0
 

Author Comment

by:NJordan72
ID: 6488208
I am using .NET.. Thanks for the responses!
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 6488230
I would suggest picking up a copy of

Professional VB.Net
WROX Press  ISBN 1-861004-97-4

It has a very good chapter on Exception Handling (Chapter 9)

Arthur Wood
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question