nus-cs2030 / 2021-s1

27 stars 48 forks source link

PYP 19/20 Sem 2 Q4 Exceptions #555

Closed yaphuiyi closed 3 years ago

yaphuiyi commented 3 years ago

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!

image

chuashiqi commented 3 years ago

exceptions have to be caught from the most specific to the most general. this is what i did: image

darrenhoon commented 3 years ago

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

yaphuiyi commented 3 years ago

@shhiiiqqqqiiiii @darrenhoon thank u for your help! Understand the question now :D

roopaniedu commented 3 years ago

Hi could i just ask what's importance of using System.err.println instead of System.out.println for this question?

sharleneq commented 3 years ago

@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.".

roopaniedu commented 3 years ago

@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?