common exception types in c sharp












common exception types in c sharp

Details of exception types in c#

Common Exception Types
The following exception types are used widely throughout the CLR and .NET Framework. You can throw these yourself or use them as base classes for deriving custom exception types.
Thrown when a function is called with a bogus argument. This generally indicates a program bug.
Subclass of ArgumentException that’s thrown when a function argument is (unexpectedly) null.
Subclass of ArgumentException that’s thrown when a (usually numeric) argument is too big or too small. For example, this is thrown when passing a negative number into a function that accepts only positive values.
Thrown when the state of an object is unsuitable for a method to successfully execute, regardless of any particular argument values. Examples include reading an unopened file or getting the next element from an enumerator where the underlying list has been modified partway through the iteration.
Thrown to indicate that a particular functionality is not supported. A good example is calling the Add method on a collection for which IsReadOnly returns true.
Thrown to indicate that a function has not yet been implemented.
Thrown when the object upon which the function is called has been disposed. Another commonly encountered exception type is NullReferenceException. The CLR throws this exception when you attempt to access a member of an object whose value is null (indicating a bug in your code). You can throw a NullReferenceException directly (for testing purposes) as follows:
throw null;

Leave A Reply

Your email address will not be published.