Closed yaphuiyi closed 3 years ago
exceptions have to be caught from the most specific to the most general. this is what i did:
I think the crux of the qn is to test students on whether they know which exception to catch first. so in this case,
FileIOException :> FileNotFoundException FileIOException :> FileMetadataException :> IncorrectPermissionException FileIOException :> FileMetadataException :> IncorrectSizeException
which means the try-catch block should catch IncorrectSizeException, IncorrectPermissionException, FileMetadataException, FileNotFoundException, FileIOException in this order
@shhiiiqqqqiiiii @darrenhoon thank u for your help! Understand the question now :D
Hi could i just ask what's importance of using System.err.println instead of System.out.println for this question?
@bitz-nobel Hi I think that there is not much difference using either, perhaps this reading could be useful in better understanding System.err, System.out and System.in : http://tutorials.jenkov.com/java-io/system-in-out-error.html#system-err Please do correct me if I'm wrong!
As quoted from the website on System.err, "System.err is a PrintStream. System.err works like System.out except it is normally only used to output error texts. Some programs (like Eclipse) will show the output to System.err in red text, to make it more obvious that it is error text.".
@sharleneq thanks for the reply! Yep I googled the differences but was kinda unsure on which would be accepted in the exam for this type of question. So there wouldn't be any problem if I were to use either one right?
May I ask how do you approach this question? Since some of the exceptions extends from other exceptions, is there something special we need to do, like throwing the IncorrectPermissionException and IncorrectSizeException first? Would appreciate if you could clear this confusion for me, thank you!