System.Exception的 [英] System.Exception

查看:54
本文介绍了System.Exception的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有没有改变系统的方法。例外。派生的消息属性

异常的构造函数?我需要运行时类''信息来初始化

这个属性,但它只是readonly。


Thaks。

Hi

Is there any method to change System. Exception. Message property in derived
exception''s constructor? I need runtime class'' information to initialize
this property, but it''s readonly.

Thaks.

推荐答案

Ivan A.< iv ************ @ hotmail.com>写道:
Ivan A. <iv************@hotmail.com> wrote:
有没有任何方法可以改变系统。例外。派生的
异常'的构造函数中的Message属性?我需要运行时类''信息来初始化
这个属性,但它只是readonly。
Is there any method to change System. Exception. Message property in derived
exception''s constructor? I need runtime class'' information to initialize
this property, but it''s readonly.




在调用基础构造函数时传入它。例如:


公共类FooException:异常

{

public FooException(string message):base(message)

{

}

}


-

Jon Skeet - < sk *** @ pobox.com>
http:// www。 pobox.com/~skeet

如果回复小组,请不要给我发邮件



Pass it in in the call to the base constructor. For example:

public class FooException : Exception
{
public FooException (string message) : base (message)
{
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too





Thanx用于回复,但基类构造函数在我可以在我自己的构造函数中执行

之前被调用,所以这不能解决我的问题。


" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...
Hi

Thanx for reply, but base class constructor is called before I can do
something in my own constructor so this is not solution to my problem.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ivan A.< iv ************ @ hotmail.com>写道:
Ivan A. <iv************@hotmail.com> wrote:
有没有任何方法可以改变系统。例外。
派生异常的构造函数中的Message属性?我需要运行时类''信息来初始化
这个属性,但它只是readonly。
Is there any method to change System. Exception. Message property in derived exception''s constructor? I need runtime class'' information to initialize
this property, but it''s readonly.



在调用基础构造函数时传入它。例如:

public class FooException:Exception
{public FooException(string message):base(message)


Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该群组,请不要给我发邮件



Pass it in in the call to the base constructor. For example:

public class FooException : Exception
{
public FooException (string message) : base (message)
{
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



Ivan,

除了将它传递给构造函数之外,如果你要创建派生的

类,你可以覆盖Message属性。


还记得Exception.Message用于用户显示,

Exception.ToString包含运行时类信息"凭借

堆栈跟踪属性。


希望这有帮助

Jay


Ivan A. < 4 ************ @ hotmail.com>在消息中写道

news:eF ************** @ tk2msftngp13.phx.gbl ...
Ivan,
In addition to passing it to the constructor, if you are creating a derived
class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class'' information" by virtue of the
stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...


有没有改变系统的方法。例外。
派生异常的构造函数中的Message属性?我需要运行时类''信息来初始化
这个属性,但它只是readonly。

Thaks。
Hi

Is there any method to change System. Exception. Message property in derived exception''s constructor? I need runtime class'' information to initialize
this property, but it''s readonly.

Thaks.



这篇关于System.Exception的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆