When to use Try...Catch

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!
NJordan72Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Arthur_WoodConnect With a Mentor Commented:
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
 
JoebobCommented:
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
 
Arthur_WoodCommented:
I took the question as refering to VB.NET --which DOES suport Try..CAtch..Finally...
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
JoebobCommented:
True, I seldom think about .Net since it will be in beta for many months to come.
0
 
NJordan72Author Commented:
I am using .NET.. Thanks for the responses!
0
 
Arthur_WoodCommented:
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
All Courses

From novice to tech pro — start learning today.