[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

When to use Try...Catch

Posted on 2001-09-17
6
Medium Priority
?
183 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

872 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