The main concept of this assignment is exception classes and how they are used handling certain runtime errors.

Objectives to be met:

  • Demonstrate how to define one or more Exception classes.
  • Demonstrate where to test for an error condition and how to throw (raise) an exception.
  • Demonstrate how to catch and handle an exception

I have provided a group of related account classes and a test program to help you focus on just exceptions and exception handling. You will write one small exception class that will be used to modify the account classes so that certain functions might throw an exception of this type. These functions will perform some test, which if true will throw an exception these functions will not handle the exception, only test for and possibly throw an exception.

In the main program (driver function), you will modify what you see to try and catch the exceptions. The statements that should cause an exception error are commented, so you can test your exceptions by removing the comments one-by-one. Remember that once an exception is thrown the remaining try block is skipped, so you should test each statement individually. All that is required in an exception handler block for this assignment is to print a message that an exception was caught.

The exception class you will write, with at least a 0-arg constructor, is as follows:

class AccountOverdrawnException

The account class functions that you will modify are as follows:


  • withdraw function throws AccountOverdrawnException when amount exceeds balance
  • transfer function throws AccountOverdrawnException when amount exceeds balance

CheckingAccount: modify inherited functions as necessary

SavingsAccount: modify inherited functions as necessary

TimeDepositAccount: modify inherited functions as necessary


Write the exception class as described; the exception class must be in its own separate .h and .cpp files.

Modify the account classes as described. (You will need to use an #include directive in the BankAccount base class in order to throw excpetions.)

Modify the test program to try-catch this type of exception with some error conditions. (You may need to use an #include directive also in the AccountTest.cpp program file in order to catch and handle exceptions.)

In addition to the required 0-argument constructor, include and demonstrate a 1-argument constructor in your exception class to report the overdrawn amount with an AccountOverdrawnException. If an account member function detects an attempt to withdraw or transfer an amount that would leave a negative balance then do not allow that to happen; instead throw the exception passing it the difference between the argument amount and balance. The exception handler should retrieve that value from the exception object and include the amount in the message. (Note: the exception class itself should not print messages; it will require a private data member and a public observer function.)

Demonstrate that in some cases, only the base class functions need to test for and throw an exception.

Add another exception class called InvalidAmountException. This exception should be used with any constructor or function that takes an amount value as an argument and which should be thrown when the amount argument is negative. The exception handler should include that amount in its error message. (Note: the exception class itself should not print messages; it will require a private data member and a public observer function.)

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.