See a hierarchy of exception classes for use in C#

The example Throw a standard exception in C# explains how to throw exceptions to indicate a problem in a program. Throwing an exception is easiest if you can find an existing exception class that correctly represents your situation. The following list shows a hierarchy of some of the most useful exception classes.

For example, if you want to make a stub or placeholder method to reserve space for code you will add later, you can use the following code to make the method throw the NotImplementedException exception.

throw new NotImplementedException(
    "The SelfDestruct method is not yet implemented.");

Now you can write other code in the program that calls this method and it will compile, but it will fail if you invoke the method at runtime.


Follow me on Twitter   RSS feed   Donate




This entry was posted in coding and tagged , , , , , , , , , , , . Bookmark the permalink.

2 Responses to See a hierarchy of exception classes for use in C#

  1. Anonymous says:

    Looks like the download link is broken.

  2. Rod Stephens says:

    Oops! Sorry. This example wasn’t supposed to have a Download button because it doesn’t have an example program. However, these related examples have downloads:

Leave a Reply

Your email address will not be published. Required fields are marked *