-
Notifications
You must be signed in to change notification settings - Fork 56
/
Program.cs
43 lines (41 loc) · 1.07 KB
/
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
40
41
42
43
using System;
using System.IO;
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);
}
}
}
}