Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

CPA: Programming

Essentials in C++ C++ INSTITUTE - PROGRAM YOUR FUTURE

Lab 7.2.1 Exceptions: simple checks


Objectives
Familiarize the student with:

situations when exceptions are thrown;


throwing exceptions;
handling exceptions.

Scenario
Write a very simple class to hold one value and its boundaries (limits of the value in integer numbers), add one method to add a value to
the one held in the instance of class, and one method to subtract a value from the one held in the object. In both methods, throw an
exception when a value exceeds the limits. In the main function create two objects and test them with different scenarios. Print the
values held at the end of the program. Add adequate try-catch blocks and an appropriate message.

Example input
5 0 10
9 0 100
15
15
90

Example output
Value could exceed limit.
Value could exceed limit.
5
24

© 2017 C++ Institute. All rights reserved. Last updated: March 07, 2017 | www.cppinstitute.org Page 1 of 1

You might also like