CSharp - Common Exception Types

Introduction

The following table lists widely used exceptions.

You can throw these exception yourself or use them as base classes for creating custom exception types.

Exception Class
Description
System.ArgumentException
Thrown when a function is called with an argument in error.
System.ArgumentNullException
Subclass of ArgumentException that's thrown when a function argument is null.
System.ArgumentOutOfRangeException
Subclass of ArgumentException that's thrown when an argument is too big or too small.
System.InvalidOperationException
indicating invalid operations on object
System.NotSupportedException
indicate that a functionality is not supported.
System.NotImplementedException
indicate that a function has not yet been implemented.
System.ObjectDisposedException
Thrown when the object on which the function is called has been disposed.
NullReferenceException
attempt to access a member of an object whose value is null.

You can throw a NullReferenceException directly (for testing purposes) as follows:

throw null;