It is indeed a good practice to log an exception at a minimum. But this practice is for exceptional situations. i.e. where you would want to check the logs if an exception is thrown so that you will have more information for fixing/improving the code. In the given situation, there is no such need because you know that the exception will be thrown, you know why that exception will be throw, and you want the exception to be thrown.
Best practices are not to be applied blindly. You need to understand why that practice is called a best practice and the reason for doing it.
About Question enthuware.ocajp.i.v7.2.842 :
Moderator: admin
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
-
- Posts: 7
- Joined: Tue Sep 19, 2023 12:11 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.842 :
I really dont understand why the first answer is better than the second one.
It is always better to add the code in catch block and log it.
it is always bad practice to have empty catch block, how can here say just for the exam, the answer 1 is correct, but the second is not!
#1 is correct, but #2 is always best practice, maybe you should change the answer?
It is always better to add the code in catch block and log it.
it is always bad practice to have empty catch block, how can here say just for the exam, the answer 1 is correct, but the second is not!
#1 is correct, but #2 is always best practice, maybe you should change the answer?
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.842 :
Thank you for your feedback. Will enhance.
Who is online
Users browsing this forum: No registered users and 6 guests