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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
entitybean
Posts: 12
Joined: Mon Apr 03, 2017 6:08 am
Contact:

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

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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, there should be a throw e;

thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Artuwok
Posts: 7
Joined: Tue Aug 20, 2019 1:32 am
Contact:

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

Post by Artuwok »

The

Code: Select all

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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Updated in the upgrade question bank now.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

wieben
Posts: 1
Joined: Thu Jun 11, 2020 2:26 pm
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Updated. Thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests