文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C#--使用Finally

C#--使用Finally

时间:2011-05-08  来源:孤独的猫

C#中可以用try..catch..Finally进行异常处理,try后面跟要执行的语句,catch为如有异常,对异常进行处理,Finally做清理工作,这部分必须执行,如下示例:

 1 /*
2 Example13_1.cs illustrates a try, catch, and finally block
3 */
4
5 using System;
6
7 class Example13_1
8 {
9
10 public static void Main()
11 {
12
13 try
14 {
15
16 // code that throws an exception
17 int zero = 0;
18 Console.WriteLine("In try block: attempting division by zero");
19 int myInt = 1 / zero; // throws the exception
20 Console.WriteLine("You never see this message!");
21
22 }
23 catch
24 {
25
26 // code that handles the exception
27 Console.WriteLine("In catch block: an exception was thrown");
28
29 }
30 finally
31 {
32
33 // code that does any cleaning up
34 Console.WriteLine("In finally block: do any cleaning up here");
35
36 }
37
38 }
39
40 }
相关阅读 更多 +
排行榜 更多 +
我的武侠梦手游下载

我的武侠梦手游下载

角色扮演 下载
快乐连连看下载免费版

快乐连连看下载免费版

休闲益智 下载
泛滥死者布道手机版下载

泛滥死者布道手机版下载

角色扮演 下载