Page 1 of 1

About Question enthuware.ocpjp.ii.v11.2.3309 :

Posted: Wed Jun 26, 2019 1:04 pm
by entitybean

Code: Select all

public String[] getDataForUser(String userid) throws ServerException{
     try{
         String dbdata = loadFromDB(userid);
         String filedata = loadFromFile(userid);
         return new String[]{dbdata, filedata};
     }catch(SQLException|IOException se){
         ServerException e = new ServerException("Unable to load data");
         e.setCause(se);
     }
     return null;
}
I find it very confusing and misleading that this newly created ServerException e is not thrown in the catch block!
Please note that the method declares "throws ServerException"!
So how can this be "a good approach to exception handing..." like the (correct) answer 1 says?
Is it possible that there is a

Code: Select all

throw e;
missing in the catch block?

Re: About Question enthuware.ocpjp.ii.v11.2.3309 :

Posted: Wed Jun 26, 2019 1:10 pm
by admin
Yes, there should be a throw e;

thank you for your feedback!

Re: About Question enthuware.ocpjp.ii.v11.2.3309 :

Posted: Thu Nov 21, 2019 7:44 am
by Artuwok
The

Code: Select all

throw e;
is still missing, so the answer is not clear.

Re: About Question enthuware.ocpjp.ii.v11.2.3309 :

Posted: Thu Nov 21, 2019 8:19 am
by admin
Updated in the upgrade question bank now.
thank you for your feedback!

Re: About Question enthuware.ocpjp.ii.v11.2.3309 :

Posted: Sun Jun 14, 2020 4:47 am
by wieben
Currently the code in the question does not compile due to the line after the catch block:
return null;
Compiler error "Unreachable statement"
Once this line is removed it compiles.

Re: About Question enthuware.ocpjp.ii.v11.2.3309 :

Posted: Sun Jun 14, 2020 4:52 am
by admin
Updated. Thank you for your feedback!