All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQLSERVER2005的混和身份验证模式的设置以及SA登陆问题_[SQL Server教程]
PHP学习:关于Zend,Optimizer_php资料_编程技术
C#中继承窗体概述及创建
ASP.NET实例:在GridView使用HyperLinkField,属性的链接_[Asp.Net教程]
Apache Web 服务器的完全安装指南_[PHP教程]
叩开C#之门系列之几个重要名词_[Asp.Net教程]
ASP.NET状态管理_[Asp.Net教程]
十天学会ASP.net,第四天_.net资料_编程技术
ASP.NET技巧:將datagrid控件內容輸出到excel文件_[Asp.Net教程]
文章,记录按内容分页显示,根据文章内容按字数进行分页_[Asp.Net教程]
Reading number is top 10 pictures
50个至今影响世界的德国发明
Ashlynn Brooke a group sexy photo2
Discharge accidentally Actresses by the breast4
Beauty is thus produced
Sell the barbecue as says father du breul5
Get girl by your hand
可爱的狗熊们
The real super beauty6
深圳的风光
Shandong jinan is about to dismantle a one hundred-year history of the building
Download software ranking
matrix2
XML+Web+Service开发教程
linux高级编程
VeryCD电驴(EasyMule) V1.1.9 Build09081
Tram sex maniac 2 (H) rar bag6
Ashlynn Video5
Call Of Duty5
变速齿轮3.26
Sora aoi, the maid, students' uniforms
Prostitutes diary
qq published in(发表于) 2014/7/11 9:20:13 Edit(编辑)
C#中的try

C#中的try

C#中的try-catch语句使用方法

C#中的try-catch语句使用方法

try-catch错误处理表达式允许将任何可能发生异常情形的程序代码放置在try{}程序代码块进行监控,真正处理错误异常的程序代码则被放置在catch{}块内,一个try{}块可对应多个catch{}块。

示例

try-catch语句写入多个catch的使用

通过两个catch语句进行捕获异常,它们分别是ArgumentNullException异常和Exception异常。程序代码如下:

using System;

class MainClass

{

static void ProcessString(string str)

{

if (str == null)

{

throw new ArgumentNullException();

}

}

static void Main()

{

// http://www.isstudy.com

Console.WriteLine("输出结果为:");

try

{

string str = null;

ProcessString(str);

}

catch (ArgumentNullException e)

{

Console.WriteLine("{0} First exception.", e.Message);

}

catch (Exception e)

{

Console.WriteLine("{0} Second exception.", e.Message);

}

}

}


键运行程序,运行结果如图1所示。



图1 try-catch语句

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Text;

namespace _3_16

{

class Program

{

static void ProcessString(string str)

{

if (str == null)

{

throw new ArgumentNullException();

}

}

static void Main()

{

// http://www.isstudy.com

Console.WriteLine("输出结果为:");

try

{

string str = null;

ProcessString(str);

}

catch (ArgumentNullException e)

{

Console.WriteLine("{0} First exception.", e.Message);

}

catch (Exception e)

{

Console.WriteLine("{0} Second exception.", e.Message);

}

}

}

}




添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.