























刚才在书上看到了一个介绍异常的代码,程序如下:
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
有一个问题想问问,在书上说可以不在catch后的括号内指定异常类型和变量名,如果不指定就意味着使用所有异常类的基类,也就是Exception类,但是我将第19行catch括号中的类型名和变量名去掉后,编译不过,这是为什么呢?希望得到大家的帮助。谢谢
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。