Help required, I do not understand how to do this Exception?
Hi,
I have to complete this question
" Handling exceptions
Write a program that reads integers in from a file, adds them up (you dont need to store them just read the number add it to the total and move to the next number) and displays the total. Make this work before you try to handle any exceptions that may happen.
Once you have the above working try the following
Firstly check for a missing file can you catch that error and print out a suitable error message. Check it works change the file name to an invalid one and run what happens?
Then try handling incorrect data in the file what if there is a double or a string in the file can you stop the programming crashing and end the program? What is the best way to do this? Then test it works put some invalid data in the file and run the program again what happens?
"
I am really unsure which kind of exception or what It is I need to be doing,
Thanks!
Re: Help required, I do not understand how to do this Exception?
If you run your code with a bad file name, the JVM will show you exactly what exception you should be catching. Same for the file having bad data. Why not try this and see what exceptions the JVM gives you.
Re: Help required, I do not understand how to do this Exception?
I think I understand what you're saying, thank you, I'll try that.