Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

When to use Try...Catch

Posted on 2001-09-17
6
Medium Priority
?
182 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 60 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 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