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

查看:87
本文介绍了是否有内置的.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?

推荐答案

InvalidOperationException 也许?


方法调用对对象的当前状态无效时抛出的异常。

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

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

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