As mentioned before, exceptions should be kept for exceptional circumstances where the executing piece of code cannot make any further meaningfully defined attempts to rectify a problematic situation. Big categories of exception types to keep in mind here include input validation and signaling of the inability (for various reasons) to process the call successfully.
Throwing an exception is simply done by use of the
throw statement in C#, specifying an object that derives from
System.Exception, specifying a meaningful message:
throw new InvalidOperationException("The object is in an invalid state.");
The CLR allows any managed object to be thrown as an exception, again for cross-language interoperability ...