If I have a try/catch block which catches an IndexOutOfBounds exception, but in the same code, I want to access a file, is it possible to do a general excepction which could catch an IOException too?
Normally when I use try/catch I just put the exception type, but I have never tried it before. Is it wrong to do so or just bad practice?
try {
// code to access a File which does not exist and inserts into an array index which does not exist
} catch (Exception eitherException){
// prints "An exception happened"
}
Would I need nested blocks, multiple catch clauses or is this ok? I have researched online for a while but cannot find an answer. Thank you!