-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptionsss.cs
42 lines (40 loc) · 1.32 KB
/
exceptionsss.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
using System;
using System.IO;
namespace ExceptionsTutorial
{
class Program
{
static void Main(string[] args)
{
StreamReader streamReader = null;
try
{
streamReader = new StreamReader(@"C:\abel.shongwe Desktop\content/seee.txt");
Console.WriteLine(streamReader.ReadToEnd());
}
catch (FileNotFoundException e)
{
/*Console.WriteLine(e.FileName);
Console.WriteLine(e.Message);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(e.StackTrace);*/
Console.WriteLine("Please Check if the file {0} exists",e.FileName);
}
//put general exceptions at the bottom and more specific ones at the top
catch (Exception e)
{
Console.WriteLine("Please check if the file {0} exists", e.Message);
}
//Its important for releasing sources properly even in case of an exception at catch blocks
finally
{
if (streamReader != null)
{
streamReader.Close();
}
Console.WriteLine("Finally Block");
}
}
}
}