VB.NET-INFORMATIONS.COM



VB.NET Language Basics Tutorials

How to VB.NET Exceptions

How to VB.NET Exceptions

Exceptions are the occurrence of some condition that changes the normal flow of execution . For ex: you programme run out of memory , file does not exist in the given path , network connections are dropped etc. More specifically for better understanding , we can say it as Runtime Errors .

In .NET languages , Structured Exceptions handling is a fundamental part of Common Language Runtime . It has a number of advantages over the On Error statements provided in previous versions of Visual Basic . All exceptions in the Common Language Runtime are derived from a single base class , also you can create your own custom Exception classes. You can create an Exception class that inherits from Exception class .

You can handle Exceptions using Try..Catch statement .

  Try
	code
	exit from Try
  Catch [Exception [As Type]]
	code - if the exception occurred this code will execute

exit from Catch

Finally

The code in the finally block will execute even if there is no Exceptions. That means if you write a finally block , the code should execute after the execution of try block or catch block.

  Try
	code
	exit from Try
  Catch [Exception [As Type]]
	code - if the exception occurred this code will execute
	exit Catch
  Finally

code - this code should execute , if exception occurred or not

From the following VB.NET code , you can understand how to use try..catch statements. Here we are going to divide a number by zero .

VB.NET Source Code


When you execute this program you will "Exception catch here .." first and then "Finally block executed " . That is when you execute this code , an exception happen and it will go to catch block and then it will go to finally block.

VB.NET Language Basics Related Contents
VB.NET data types
VB.NET Implicit conversion and Explicit Conversion
VB.NET Access Specifiers
VB.NET Option Explicit
VB.NET Option Strict
VB.NET On Error

VB.NET Related Tpoics
Microsoft .Net Framework Tutorials
VB.NET Language Basics Tutorials
VB.NET Program Flow Control Tutorials
VB.NET Collections Tutorials
VB.NET String Tutorials
VB.NET Files Tutorials
VB.NET Excel 2007 Tutorials
VB.NET Crystal Reports Tutorials
VB.NET Communications Tutorial
VB.NET ADO.NET Tutorial with source code
ADO.NET Data Providers help and Tutorial
VB.NET ADO.NET Dataset Tutorial
ADO.NET DataAdapter and Dataset
VB.NET ADO.NET DataView Tutorial

Search here for more Vb.Net Source Code :


   Categories

    HOME
    VB.NET

 
 
 
   













  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2008 All Rights Reserved