Java Programming - Assertions - Discussion

Discussion Forum : Assertions - Pointing out the correct statements (Q.No. 4)
4.
Which of the following statements is true?
It is sometimes good practice to throw an AssertionError explicitly.
Private getter() and setter() methods should not use assertions to verify arguments.
If an AssertionError is thrown in a try-catch block, the finally block will be bypassed.
It is proper to handle assertion statement failures using a catch (AssertionException ae) block.
Answer: Option
Explanation:

Option A is correct because it is sometimes advisable to thrown an assertion error even if assertions have been disabled.

Option B is incorrect because it is considered appropriate to check argument values in private methods using assertions.

Option C is incorrect; finally is never bypassed.

Option D is incorrect because AssertionErrors should never be handled.

Discussion:
1 comments Page 1 of 1.

Sheetal said:   1 decade ago
What is assertion?

Post your comments here:

Your comments will be displayed after verification.