CptS 122 – Data Structures                                                                         

 

Lab 10: Exception Handling in C++

 

Assigned: Week of October 29, 2012

Due: At the end of the lab session

 

I. Learner Objectives:

 

At the conclusion of this programming assignment, participants should be able to:

 

II. Prerequisites:

 

Before starting this programming assignment, participants should be able to:

 

III. Overview & Requirements:

 

This lab, along with your TA, will help you navigate through designing, implementing, and testing exception handling in C++.

 

Labs are held in a “closed” environment such that you may ask your TA questions. Please use your TAs knowledge to your advantage. You are required to move at the pace set forth by your TA. Please help other students in need when you are finished with a task. You may work in pairs if you wish. However, I encourage you to compose your own solution to each problem. Have a great time! Labs are a vital part to your education in CptS 122 so work diligently.

Tasks:

NOTE: These problems are derived from Deitel & Deitel’s C How To Program textbook.

1. Use inheritance to create various derived classes of runtime_error (we implemented DivideByZeroException in class). Then show that a catch handler specifying the base class can catch derived-class exceptions (Exercise 24.22).

 

2. Write a program that generates and handles a memory-exhaustion exception. Your program should loop on a request to create dynamic memory through operator new.

 

3. Write a program illustrating that all destructors for objects constructed in a block are called before an exception is thrown from that block (Exercise 24.24).

 

4. Write a program illustrating that the order of exception handlers is important. The first matching handler is the one that executes. Attempt to compile and run your program two different ways to show the two different handlers execute with two different effects (Exercise 24.27).

 

IV. Submitting Labs:

 

V. Grading Guidelines: