Exceptions
Video
I have provided some complete working functions in functions.h
you dont know exactly what they are going to do and you do not have the source to look at them
THEY do throw exceptions, you do not know the data type or the value that they throw.
you will finish a menu driven main to call the completed functions in functions.h
Select Option (1-3)
1. PrintFile
2. Test StrToInt
3. Test StrToDbl
4. PrintFile (repeat till success)
5. Test IsBetween
6. Exit
each of the provided functions WILL throw exceptions if you pass them incorrect values
your job is write the catch blocks for the main for all of the exceptions.
at the end no matter what bad data you enter the only time the program should stop running is when you type 6 to exit
you will need ONE and ONLY ONE main try block with muliple catch blocks
put all of your logic to call the 4 functions inside the single try block
your output should match that of the example with the exclusion that yours should have the actual data type of the exception instead of ???
you would have something like
cout << "exception caught of type (int/char/string), val=" << the_value_cought << "\n\n";
the value cought is what is passed to your exception NOT something you typed in
if the cout statements inside your catch blocks are not pretty much exaclty what is above you are doing it wrong.
IMPORTANT!!!!!
you will need to add your catch blocks one at a time.....
the code is there for option 1, test it fully , once you put in a bad value.. ie ask it to open a file that does not exist it will exit and say there is a an uncought exception
then and ONLY then add a catch block for the exception type that causes the program to stop executing and that exception type ONLY
once your program matches the output of the example exactly then proceed
NOTE: "'std::__cxx11::basic_string, std::allocator >'" is just "std::string" so if you see that just catch std::string
once you have a catch block that works for case 1 and your output matches the example start working on case 2, when your program stops because of an uncough exeption in case 2
add a try block for that type of exception.
DO NOT just start adding catch blocks for random data types , if there is a unneeded catch block I will know you did not follow the directions and grade accordinly
if running your code results in an un caught exception add a catch block for that type
when asked for a file name give it name of a file that does not exist .. see what the example does when you provide a bad file name
option 2
make the output of your program match the example THE ONLY difference should be that yours should not have ??? , replace ??? with the type of exception .. string, const char *, int and so on
try to convert "dumpling", "55a", "5.5" and "55"
option 3
make the output of your program match the example THE ONLY difference should be that yours should not have ???
try to convert "dumpling", "55", "5.5.5" and "5.5"
option 4 is slightly different DO IT LAST
you will use a try and catch just for this call, your catch block will not have any code in it.. you want to ignore the bad filename exception and simply ask them to enter the filename again
you can use a while loop... while (true)
it will loop forever until you put in a valid filename then it will print the file. if it cannot find the file it does not display an error
it simply asks you to type in the filename again
after you have successfully read the file you can use break to get out of the while loop
option 5
make the output of your program match the example THE ONLY difference should be that yours should not have ???
try with a low of 5 and high of 10... and try with i high of 5 and low of 10
a low of 10 and high of 5 is NOT a valid range and should trigger an exception
be sure to type exit to close your terminal, dont just close the window without typing exit