Is there a built-in .NET exception that indicates the state of an illegal object?

What exception should I make if I encounter an illegal state - for example, an initialization method that should only be called once, when it is called a second time? I really don't see any built-in exception that makes sense. This is like something that should be in the framework - I will not poke in the right place?

+51
c # exception
Nov 03 '08 at 20:17
source share
2 answers

InvalidOperationException maybe?

An exception that is thrown when a method call is invalid for the current state of an object.

+65
Nov 03 '08 at 20:19
source share

If at all I would say that a System.InvalidProgramException will get closest to what you want. What is wrong if you choose a special exception?

-3
Nov 03 '08 at 20:26
source share



All Articles