This may be a dumb question, but I haven't been able to find the answer anywhere else. I have a class that will read and write to a file for saves. Now, I'm trying to handle some possible errors that could come my way. What I want to know is if this is legal or common practice in Java:
try {
in = new ObjectInputStream(new FileInputStream(fileName));
score = (Score)in.readObject();
} catch() {
...
}
The problem I'm having is if the file is empty, it cannot read the file. The program will crash, so I want to know is common or regular practice to create some data in the file from the catch statement, then try/catch it again. Then at the second catch I can crash the program.
The reason I have for wanting to do it this way is in the case that the user erases the data in the file.
If it's legal, would this be the syntax?
try {
// try something here
} catch(//Exception here) {
// Create a new file and try again.
try {
// try again
} catch() {
// Crash the program
}
}