Solved

When to use Try...Catch

Posted on 2001-09-17
6
174 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 65
MS Date Picker 64 bit 32 bit issue 12 49
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 40
VB6 ListBox Question 4 30
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

4 Experts available now in Live!

Get 1:1 Help Now