Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>See <a href="http://msdn.microsoft.com/en-us/library/ms173163.aspx" rel="noreferrer">Creating and Throwing Exceptions</a>.</p> <p>On throwing built-in exceptions, it says:</p> <blockquote> <p>Do not throw System.Exception, System.SystemException, System.NullReferenceException, or System.IndexOutOfRangeException intentionally from your own source code.</p> </blockquote> <p>and</p> <blockquote> <p>Do Not Throw General Exceptions </p> <p>If you throw a general exception type, such as Exception or SystemException in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle. </p> <p>Instead, either throw a more derived type that already exists in the framework, or create your own type that derives from Exception."</p> </blockquote> <p>This <a href="http://blogs.msdn.com/fxcop/archive/2007/01/22/faq-what-exception-should-i-throw-instead-of-the-reserved-exceptions-found-by-donotraisereservedexceptiontypes.aspx" rel="noreferrer">blog entry</a> also has some useful guidelines.</p> <p>Also, FxCop code analysis defines a list of "do not raise exceptions" as <a href="http://msdn.microsoft.com/en-us/library/ms182338.aspx" rel="noreferrer">described here</a>. It recommends:</p> <blockquote> <p>The following exception types are too general to provide sufficient information to the user: </p> <ul> <li>System.Exception </li> <li>System.ApplicationException </li> <li>System.SystemException</li> </ul> <p>The following exception types are reserved and should be thrown only by the common language runtime: </p> <ul> <li>System.ExecutionEngineException </li> <li>System.IndexOutOfRangeException </li> <li>System.NullReferenceException </li> <li>System.OutOfMemoryException</li> </ul> </blockquote> <p>So in theory you can raise any other framework exception type, providing you clearly understand the intent of the exception as described by Microsoft (see MSDN documentation).</p> <p>Note, these are "guidelines" and as some others have said, there is debate around System.IndexOutOfRangeException (ie many developers throw this exception).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload