从财产中抛出异常 [英] Throwing Exceptions from Property

查看:85
本文介绍了从财产中抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大师,


我想知道是否从对象的

属性中抛出异常是对的。

为了进一步深入,在'get''

操作期间可以抛出异常吗?


我正在寻找MS关于抛出异常的文章。但是,徒劳无功。


我很想知道更多。


-Sek

Gurus,

I am wondering whether it is right to throw an exception from a
Property of an object.

To get into it further, is it okay to throw exception during ''get''
operation?

I was searching for MS articles on throwing exceptions. But, in vain.

I am curious to know more on this.

-Sek

推荐答案

不好。因为他们想知道普通的例外

obj.Name =" name";


如果你需要为此抛出异常使用方法,它更期待
Not good. Because they wonder to get exception from the common
obj.Name = "name";

If u need to throw exception use method for this, it''s more expected
Gurus,
我想知道从对象的
属性中抛出异常是否正确。
进一步了解,在获取操作期间是否可以抛出异常?

我正在搜索关于抛出异常的MS文章。但是,徒劳无功。

我很想知道更多。
Gurus,
I am wondering whether it is right to throw an exception from a
Property of an object.
To get into it further, is it okay to throw exception during ''get''
operation?

I was searching for MS articles on throwing exceptions. But, in vain.

I am curious to know more on this.




-

WBR,

Michael Nemtsev ::博客: http://spaces.msn。 com / laflour


有时一个人仍忠于某一事业,因为它的对手不会因为b $ b不再是平淡无奇的。 (c)Friedrich Nietzsche



--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


感谢您的信息。


但是,在''期间抛出异常怎么样? '设置''操作。我没有看到

任何其他方式来解决Set操作的失败。

Thanks for the info.

But, how about throwing exception during a ''Set'' operation. I don''t see
any other way of converying the failure of ''Set'' operation.


为什么不呢?属性只是方法调用的语法糖果。它们实际上是IL代码中的方法调用。它们通常用于预先生成
或对值进行后处理以验证它。所以它当然可以

如果价值无效则抛出异常。


Leon Lambert


Sek写道:
Why not? Properties are just syntactic candy for a method call. They are
actually method calls in the IL code. They are typically used to do pre
or post processing of the value to validate it. So it certainly could
throw an exception if the value is invalid.

Leon Lambert

Sek wrote:
Gurus,

我想知道从对象的
属性中抛出异常是否正确。

要获得进一步说,在'get''
操作期间可以抛出异常吗?

我正在搜索关于抛出异常的MS文章。但是,徒劳无功。

我很想知道更多。

-Sek
Gurus,

I am wondering whether it is right to throw an exception from a
Property of an object.

To get into it further, is it okay to throw exception during ''get''
operation?

I was searching for MS articles on throwing exceptions. But, in vain.

I am curious to know more on this.

-Sek



这篇关于从财产中抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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