Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Throw an AssertionError explicity?

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the K&B bonus master exam, we have the following question:

Which are true? (Choose all that apply.)
A It's not good practice to place assertions where you think execution where you think execution should never reach.

B It is sometimes appropriate to call getters and setters from assertions.

C Use assertions to verify the arguments of private methods.

D Assertions can be disabled for a particular class.

E Never throw an AssertionError explicitly.

The given answer is C && D. I think E is also right. Could you guys give me an example where we need to throw an AssertionError explicitly?

Thanks,
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer in the book is correct."Throw" should not be associated with Assertions(Bad practice).Assertions are to help you test your assumptions and tell you if you are wrong.They return false in such case.If you are trying to "Catch" the error ,as a programmer you have coded wrongly.Therefore "handling" beats the whole point of assertions.
 
Yeming Hu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahul siddharth:
The answer in the book is correct."Throw" should not be associated with Assertions(Bad practice).Assertions are to help you test your assumptions and tell you if you are wrong.They return false in such case.If you are trying to "Catch" the error ,as a programmer you have coded wrongly.Therefore "handling" beats the whole point of assertions.



Didn't get you. It seems you agree with the point we should never throw AssertionError. Therefore the E should be a correct answer.
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the following link within the Ranch has an equal discussion so you could have a look at it

Throw Assertions Explicit
 
Yeming Hu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Remko Strating:
the following link within the Ranch has an equal discussion so you could have a look at it

Throw Assertions Explicit



Thanks a lot!
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic