O'Reilly logo

C# Primer Plus by Klaus Michelsen

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

Writing Custom Exceptions

The .NET Framework's built-in exception classes will accommodate most abnormal conditions you encounter. However, when you need additional capabilities, you can write your own custom-made exception classes by using System.ApplicationException as a base class.

Lines 3–26 of Listing 19.7 illustrate this possibility by defining a new exception class called LogarithmicException.

Listing 19.7. CustomException.cs
 01: using System; 02: 03: public class LogarithmicException : System.ApplicationException 04: { 05: private uint errorNumber; 06: 07: 08: public LogarithmicException() : base("Logarithmic exception") 09: { 10: errorNumber = 1000; 11: } 12: 13: 14: public LogarithmicException(string message, uint initErrorNumber) ...

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