• Post Reply Bookmark Topic Watch Topic
  • New Topic

assertion  RSS feed

 
Arun Prasath
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why is it not recommended to use assertion in public methods(arguments)?
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because a public method might be called from code which you don't control and the assertions are not guaranteed to run. Because you can enable or disable them. So checking on public arguments should be done in a different way.

You could throw an Exception when an argument isn't valid.
 
Arun Prasath
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi remko,
how do you say that assertions are not gauranteed to run in
public methods?
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Leave aside the fact that whether they are gauranteed to run or not. Giving an AssertionError for an invalid input to a public method doesn't seem right. As to why Assertions can be off sometime you need this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!