Hi guys,
I'm really confused about what should I consider as good or bad practice when explicitly throwing an Error for the exam.
The following two questions were extracted from K&B Master Exam #2 and from Complete
Java 2 Certification Study Guide 5th Edition, respectively.
It seems the first one doesn't consider throwing explicitly an Error as bad practice whereas the second one considers throwing explicitly an Error as a bad practice.
So now I'm really confused about what should I consider as true.
Please I'm really interested about your comments.
Please check it out :
-------------------------------------------
From K&B Master Exam #2.
Which are true ? (Choose all that apply)
a) It's not good practice to place assertions where you think execution should never reach.
b) It's sometimes appopriated to call getters and setters from assertions.
c) Use assertions to verify arguments of private methods.
d) Assertions can be disabled for a particular class.
e) Never throw an AssertionError explicitly.
C and D are correct but I thought the correct answers were C, D and E.
-------------------------------------------
Complete Java 2 Certification Study Guide 5th Edition
When is it appropriate to write code that constructs and throws an error?
a) When a public method�s preconditions are violated
b) When a public method�s postconditions are violated
c) When a nonpublic method�s preconditions are violated
d) When a nonpublic method�s postconditions are violated
e) Never
The correct answers is E. According to author's explanation the reason is : "It is never appropriate for application programmers to construct and throw errors."
Once Error is the super class of AssertionError. I think Both questions are totally related to each other.
[ April 14, 2006: Message edited by: Edisandro Bessa ]