O'Reilly logo

Applied Microsoft® .NET Framework Programming by Jeffrey Richter

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

Defining Your Own Exception Class

When implementing your methods, you might come across scenarios in which you want to throw an exception. For example, I recommend that your nonprivate methods always validate their arguments, and if any argument doesn’t live up to your method’s implicit assumptions, an exception should be thrown. In this case, I recommend that you throw one of the exception classes already defined in the FCL: ArgumentNullException, ArgumentOutOfRangeException, or DuplicateWaitObjectException.

I strongly suggest that you throw a specific exception class, a class that has no other classes derived from it. For example, don’t throw an ArgumentException because it’s too vague, it could mean any of its three derived types, and it doesn’t ...

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