关于.NET下异常的问题

刚才在书上看到了一个介绍异常的代码,程序如下:

 1using System;
 2using System.IO;
 3
 4public 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
有一个问题想问问,在书上说可以不在catch后的括号内指定异常类型和变量名,如果不指定就意味着使用所有异常类的基类,也就是Exception类,但是我将第19行catch括号中的类型名和变量名去掉后,编译不过,这是为什么呢?希望得到大家的帮助。谢谢

posted on 2005-05-27 10:45  chance_win  阅读(322)  评论(0)    收藏  举报

导航