Posted by: Sourav | August 25, 2016

Exception Example in VB,VB Teacher Sourav,Kolkata 09748184075


Option Strict On
Option Explicit On
Imports System
Imports System.IO
Module Module1

Sub Main()
Dim streamreader As StreamReader = Nothing

Try
streamreader = New StreamReader(“D:\automation youtube\data.txt”)
Console.WriteLine(StreamReader.ReadToEnd)

Catch filenotfound As FileNotFoundException
Console.WriteLine(“Please check if the file {0} exists”, filenotfound.FileName)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine(filenotfound.StackTrace)

Catch ex As Exception
Console.WriteLine(ex.Message)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine(ex.StackTrace)
Finally

If IsNothing(streamreader) Then
Else
Console.WriteLine(“finally it’s closing”)
streamreader.Close()
End If

End Try
Console.ReadLine()
End Sub

End Module

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: