Jump to content

Common C# Exception Types

  chco's Photo
Posted Aug 13 2010 01:33 PM

Below we have a list of the common C# exception types taken as an excerpt from C# 4.0 Pocket Reference, Third Edition.
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.

Note: In Framework 4.0, Code contracts eliminate the need for ArgumentException (and its subclasses). Code contracts are covered in Chapter 13 of C# 4.0 in a Nutshell (O'Reilly).

C# 4.0 Pocket Reference

Learn more about this topic from C# 4.0 Pocket Reference, 3rd Edition.

When you're programming C# 4.0 and need a little help, this tightly focused and practical book tells you exactly what you need to know -- without long introductions or bloated examples. It's ideal as a succinct quick reference or as a guide to get you rapidly up to speed if you already know Java, C++, or an earlier version of C#. Written by the authors of the acclaimed C# 4.0 in a Nutshell (O’Reilly), this book covers the entire C# 4.0 language -- without skimping on the details

See what you'll learn

0 Subscribe

1 Reply

  hu_yang's Photo
Posted Mar 17 2012 10:46 AM

A small and easy tutorial of how to andli exception in c#