• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertions

 
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
Pie
Posts: 20494
54
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: 48382
56
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic