Question: Demonstrate Recursion and Exception handling Write a small java program to recursively read a file that at first does not exist. Program exception handling that

Demonstrate Recursion and Exception handling
Write a small java program to recursively read a file that at first does not exist.
Program exception handling that allows the user to correct the problem.
Track and display the consecutive number of each recursive call (see example output).
When the problem is fixed, thank the user ONLY ONCE.
Track the number of recursive returns, unwinding from the count of the deepest return (see
example output).
Example output:
Failed to open file testData.dat: iostream error
Recursive call count: 1
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 2
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 3
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 4
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 5
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 6
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 7
Please remedy the situation. Then press enter to continue.
Failed to open file testData.dat: iostream error
Recursive call count: 8
Please remedy the situation. Then press enter to continue.
Thanks for fixing that.
Recursion return count: 8
Recursion return count: 7
Recursion return count: 6
Recursion return count: 5
Recursion return count: 4
Recursion return count: 3
Recursion return count: 2
Recursion return count: 1
This is the content of the file:
Howard, Shemp
Howard, Moe
Fine, Larry
Howard, Curly
Process returned 0(0x0) execution time : 14.464 s
Press any key to continue.
My Solution:
I did this in one file with 3 functions/methods
bool fileOpen(ifstream inFile, int count) RECURSIVE CALLS TO THIS
inFile is the name of the file to open.
count is the recursion count bump this number for each call to this function/method
Returns true if this is the first return. In other words, the last call to this function/method,
where the user fixes the problem.
The try/throw catch exception handling is completely contained in this function/method
Recursive call counts are adjusted here.
Use getline() in c++ to just press enter to continue.
The return Boolean value is used to determine when to print the one time message thanking the
user for fixing the problem.
void readDataFile()
Initial the count and call fileOpen(). When this call returns, any file existence problems will have
been resolved.
Step through all the file records and display them.
Dont forget to close the file.
main()
Simply call readDataFile.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!