#882 – What Types of Exceptions to Throw
July 8, 2013 5 Comments
When you throw an exception from your code, you should throw one of the following exception types:
- One of the preexisting exception types, if the error matches the exception type (e.g. System.InvalidOperationException or System.ArgumentException)
- A custom exception type derived from System.Exception
You should not throw exceptions whose type is System.Exception, System.SystemException, System.NullReferenceException or System.IndexOutOfRangeException. These exceptions are thrown by code in the .NET Framework, but you should never throw these exceptions from your own code.