刚才在书上看到了一个介绍异常的代码,程序如下:
1
using System;
2
using System.IO;
3
4
public class ExceptionDemo
5

{
6
public static void Main()
7
{
8
StreamWriter sw = null;
9
10
try
11
{
12
sw = new StreamWriter(new FileStream("Area.txt",FileMode.Open));
13
sw.WriteLine("Hello there");
14
}
15
catch(FileNotFoundException fnfe)
16
{
17
Console.WriteLine("djslfjdsfj");
18
}
19
catch(Exception e)
20
{
21
Console.Write(e);
22
}
23
finally
24
{
25
if(sw != null)
26
{
27
sw.Close();
28
}
29
}
30
}
31
}
32

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
