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.3.1 Exceptions: file checks


Objectives
Familiarize the student with:

situations when exceptions are thrown;


handling file-related exceptions.

Scenario
Write a class that holds a (2×2) matrix, and add two methods to work with files: one method to load the matrix from a file (in any
format) and one method to save the matrix to a file (in the same format). Add code to handle exceptional situations (file not found and no
rights to file), print a message and re-throw an exception. Add a try-catch block in the proper places. Simulate both situations handled
(try to load a nonexistent file, and try to save a file in a path where you have no proper rights).

Example input
Simulate both situations handled

Example output
File not found at: path
No rights to write to file: path

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

You might also like