O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.14. The Exception Class Hierarchy

An exception must represent either an Exception class object or an object of a class derived from Exception. The class framework provides many predefined exception classes. Alternatively, we can derive our own exception classes.

Consider the member function find(). It takes two parameters: a string array and a string item. If either or both arguments are null, find() throws the predefined ArgumentNullException:

 public static bool find( string [] table, string item ) { if ( table == null || item == null ) { Exception e = new ArgumentNullException(); if ( table == null ) { e.Source = "Argument One"; if ( item == null ) e.Source += " and Argument Two"; } else e.Source = "Argument Two"; throw e; } // ... return ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required