关于.NET下异常的问题
刚才在书上看到了一个介绍异常的代码,程序如下:
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![]()
using System;2
using System.IO;3

4
public class ExceptionDemo5
{6
public static void Main()7
{8
StreamWriter sw = null;9

10
try11
{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
finally24
{25
if(sw != null)26
{27
sw.Close();28
}29
}30
}31
}32

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


浙公网安备 33010602011771号