.NET has prebuilt class libraries containing hundreds of thousands of types. Rather than creating your own completely new types, you can often start by inheriting from one of Microsoft's.
In the Ch06_PacktLibrary project, add a new class named BankAccountException
, as shown in the following code:
using System; namespace Packt.CS6 { public class BankAccountException : Exception { public BankAccountException() : base() { } public BankAccountException(string message) : base(message) { } public BankAccountException(string message, Exception innerException) : base(message, innerException) { } } }
In the BankAccount
class that you created in the previous chapter, add the following method:
public void Withdraw(decimal amount) { if ((Balance - amount) < 0M) { throw new BankAccountException("Balance cannot be less than zero!"); } else { Balance -= amount;...