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

Reading number is top 10 articles
在Windows系统下安装PHP5.0配置简明教程_php资料_编程技术
PHP实现同步远程Mysql_[PHP教程]
在ASP.NET中运用JavaScript_[Asp.Net教程]
网站?XML?我的思考_[XML教程]
SQL数据库高级教程:学习 SQL BETWEEN_[SQL Server教程]
JScript中正则表达式用法详解_JavaScript技术_编程技术
详解:——如何将图片储存在数据库里_php资料_编程技术
C#中实现VB中的CreateObject方法_.net资料_编程技术
借助HiddenText,确定CheckBoxList当前的操作类型及点击的CheckBox_[Asp.Net教程]
如何于DataGridView控件中以跨数据行方式显示数据_.net资料_编程技术
Reading number is top 10 pictures
Summer is most suitable for young people to travel in China2
人美胸美腿更美4
Absolutely shocked. National geographic 50 animal photographys4
Take you to walk into the most true north Korea rural3
The beginning and end
A man's favorite things14
Fierce! China's special forces training the devil1
代沟,真好
谁认识这位校花
如果我是导演...
Download software ranking
Unix video tutorial12
Professional killers2 data package
双旗镇刀客A
Sora aoi, the nurse, uniform ,nursing assistant
The Bermuda triangle2
Boxer Classic video3
豪门浪荡史
VeryCD电驴(EasyMule) V1.1.9 Build09081
Boxer's Top ten classic battle10
Unix video tutorial5
qq published in(发表于) 2014/7/11 9:20:11 Edit(编辑)
C#中的throw语句使用方法

C#中的throw语句使用方法

C#中的throw语句使用方法

C#中的throw语句使用方法

throw语句用于控制发出在程序执行期间出现反常情况(异常)的信号。throw语句通常与try-catch或try-finally语句一起使用。可以使用throw语句显式引发异常(这里引发自定义异常)。创建用户自定义异常,可以“Exception”作为用户自定义异常类名的结尾。

示例

throw语句的使用

本示例通过Exception派生了一个新异常类UserEmployeeException,该类中定义了3个构造函数,每个构造函数使用不同的参数,然后再抛出自定义异常。程序代码如下:

using System;

using System.Collections.Generic;

using System.Text;

using System.IO;

namespace ClsUserExecption

{

class Program

{

public class UserEmployeeException: Exception

{

private string errorinfo=string.Empty;

public UserEmployeeException()

{

}

public UserEmployeeException (string message) : base(message)

{

errorinfo = message;

}

public UserEmployeeException (string message, Exception

// http://www.isstudy.com

inner):base(message,inner)

{

errorinfo = message;

inner = null;

}

}

public static void Main()

{

try

{

throw new UserEmployeeException("error Info of use ");

}

catch (UserEmployeeException ey)

{

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

Console.WriteLine(ey.Message,ey.InnerException);

Console.Read();

}

}

}

}


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



图1 throw语句

完整程序代码如下:

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

using System;

using System.Collections.Generic;

using System.Text;

namespace _3_15

{

class Program

{

public class UserEmployeeException : Exception

{

private string errorinfo = string.Empty;

public UserEmployeeException()

{

}

public UserEmployeeException(string message)

: base(message)

{

errorinfo = message;

}

public UserEmployeeException(string message, Exception inner)

: base(message, inner)

{

errorinfo = message;

inner = null;

}

}

public static void Main()

{

try

{

throw new UserEmployeeException("error Info of use ");

// http://www.isstudy.com

}

catch (UserEmployeeException ey)

{

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

Console.WriteLine(ey.Message, ey.InnerException);

Console.Read();

}

}

}

}




添加到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.