-
Notifications
You must be signed in to change notification settings - Fork 18
/
Program.cs
39 lines (37 loc) · 913 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace NestedExceptions;
class Program
{
static void Main(string[] args)
{
try
{
ShowFirstLineLength(@"C:\Temp\File.txt");
}
catch (NullReferenceException)
{
Console.WriteLine("NullReferenceException");
}
}
static void ShowFirstLineLength(string fileName)
{
try
{
using (var r = new StreamReader(fileName))
{
try
{
Console.WriteLine(r.ReadLine()!.Length);
}
catch (IOException x)
{
Console.WriteLine("Error while reading file: {0}",
x.Message);
}
}
}
catch (FileNotFoundException x)
{
Console.WriteLine("Couldn't find the file '{0}'", x.FileName);
}
}
}