是否有一个内置的.NET异常,说明非法对象的状态? [英] Is there a built in .NET exception that indicates an illegal object state?

查看:100
本文介绍了是否有一个内置的.NET异常,说明非法对象的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该抛出什么异常,如果我遇到一个非法状态 - 例如,应该只被调用一次的初始化方法被称为第二次?我真的没有看到任何内置的例外是有道理的。这看起来似乎应该在框架 - ?我不能戳在正确的位置

What exception should I throw if I encounter an illegal state - for instance, an initialization method that should only be called once being called a second time? I don't really see any built-in exception that makes sense. This seems like something that should be in the framework - am I not poking in the right spot?

推荐答案

<一个href="http://msdn.microsoft.com/en-us/library/system.invalidoperationexception.aspx">InvalidOperationException可能?

当一个方法调用对于对象的当前状态无效时引发的异常。

The exception that is thrown when a method call is invalid for the object's current state.

这篇关于是否有一个内置的.NET异常,说明非法对象的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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