Ex:
C#
try
{
StreamReader sr = new StreamReader("example.txt");
Console.WriteLine(sr.ReadToEnd());
}
catch (System.IO.FileNotFoundException ex)
{Console.WriteLine("The file could not be found.");
}
catch (System.UnauthorizedAccessException ex)
{Console.WriteLine("You do not have sufficient permissions.");
}
catch (Exception ex)
{
Console.WriteLine("Error reading file: " + ex.Message);
}
' VB
Try
Dim sr As StreamReader = New StreamReader("example.txt")
Console.WriteLine(sr.ReadToEnd)
Catch ex As System.IO.FileNotFoundException
Console.WriteLine("The file could not be found.")Catch ex As System.UnauthorizedAccessException
Console.WriteLine("You do not have sufficient permissions.")Catch ex As Exception
Console.WriteLine("Error reading file: " + ex.Message)
End Try

0 comments:
Post a Comment