IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
VB.Net
Search VB.Net Group:

Advanced
-Collapse +Expand VB.Net To/From
To/FromCODEGuides
-Collapse +Expand VB.Net Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingVB.NetLanguage Basics   Print This     
 
VB.Net Language Basics:
VB.Net Exception Trapping (Try...Catch...Finally)
 
Posted 16 years ago on 11/25/2008
VB.Net Code Snippet:
 A flashcard from our VB.Net Flashcards Library
 A code snippet from our VB.Net Code Snippets Page

KB101647

Languages Focus: Exception Trapping

A common usage of exception handling is to obtain and use resources in a "try-it" block, deal with any exceptions in an "exceptions" block, and release the resources in some kind of "final" block which executes whether or not any exceptions are trapped.

VB.Net Exception Trapping

VB.Net uses a try...catch...finally statement to trap for errors.

Try
Catch
Finally
End Try
Syntax Example:
Try
Dim y As Integer = 0
y = 1 / y
Catch
MessageBox.Show("you cannot divide by zero")

End Try

Complete Simple Example

Here is a complete example using a button click event:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  Try
    MessageBox.Show("Before Error")
    Dim y As Integer = 0
    y = 1 / y
    MessageBox.Show("This line never executes: " + y)
  Catch
    MessageBox.Show("you cannot divide by zero")
  Finally
    MessageBox.Show("This line always executes.")
  End Try
End Sub

More Info


Comments

1 Comments.
Share a thought or comment...
Comment 1 of 2

VB.NET exception in detail with source code samples

http://vb.net-informations.com/language/vb.net_exceptions.htm

nelcon.

---
Nelcon
Posted 12 years ago

Comment 2 of 2

Finally i catch exception trapping just focus on language. A complete and simple example is also here because you are checking language and after that check exception trapping which tell you how to focus on www.resumesservicesreviews.com/resumetarget-review/ and also give you simple tips which are important.

Posted 53 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P177A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Intermediate

1 Intermediate Level Question

Question #1: Multiple Choice

Which of the following syntax templates is used for error handling?

Answer:
1. 
Try
Catch
Finally
End Try
2. 
Try
Except
Final
End Try
3. 
Try
OnFail
OnFinal
End Try
4. 
Try
Handle Exception
Do Final
End Try
5. 
Try
Exception
Cleanup
End Try

 KB Article #101647 Counter
12844
Since 11/25/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]