Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Assertions  RSS feed

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do we say these about assertions :

1. Don't use assertions to validate arguments to a public method.

2. Don't use assertions to validate command line arguements.

Any particular reason for these DON'TS.
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article on Assertions might be useful to you.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short, you cannot guarantee that assertions are turned on. Therefore all checks you think are being performed may be in fact checked. For example:
When assertions are all of a sudden turned off your validation fails and you will get a different exception, one you don't expect. Use your own checking mechanism instead:
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You use the assertions to find the places where Exceptions (as Rob has shown you) are necessary.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!