Posted by: Sourav | August 25, 2016

Inner Exception Example in VB,VB Teacher Sourav,Kolkata 09748184075


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

Module Module1

Sub Main()
Try

Try
Dim fn, sn As Integer
Dim result As Integer
fn = Convert.ToInt32(Console.ReadLine())
sn = Convert.ToInt32(Console.ReadLine())
result = CInt(fn / sn)
Console.WriteLine(“Result = {0}”, result)
Catch ex As Exception
Dim filepath As String = “D:\sample logs\ log.txt”
If File.Exists(filepath) Then
Dim sw As StreamWriter = New StreamWriter(filepath)
Console.WriteLine(“There is a problem,Please try later”)
sw.Write(ex.GetType().Name)
sw.WriteLine()
sw.Write(ex.Message)

sw.Close()

Else
Throw New FileNotFoundException(filepath + ” is not present”, ex)

End If

End Try
Catch exception As Exception
Console.WriteLine(“Current Exception = {0}”, exception.GetType().Name)
If IsNothing(exception.InnerException) = False Then
Console.WriteLine(“Inner Exception = {0}”, exception.InnerException.GetType().Name)
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: