O'Reilly logo

Special Edition Using C# by NIIT

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

User-Defined Exceptions

So far, this chapter has discussed only system-defined exception classes. However, C# also supports user-defined exception classes. These are exception classes that the users declare. This ensures that applications can be customized to produce application-specific error messages when exceptions are thrown during program execution.

There are a few restrictions on user-defined exception classes. These classes must declare the most commonly used constructors and the class name must end with the word “Exception.” It is also recommended that all user-defined exceptions be grouped under a separate namespace to enable better organization of all exception classes.

Listing 9.4 demonstrates a user-defined exception class.

Listing ...

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