Throwing Exceptions
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.");
Note: RuntimeWrappedException
The CLR allows any managed object to be thrown as an exception, again for cross-language interoperability ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access