Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assertions

 
Jui Mahajan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. The assert system is suitable as a general replacement for the try/catch clause.
2) The assert system is suitable as a general replacement for the if/else clause
Both the above statements are false. WHy ? I thought both sounded true
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is false because you can turn assertions off. You should never depend on assertions to make your program run -- they should be used during development to insure that unexpected situatioins / variable values do not occur. They are generally turned off in production (it speeds things up). So if you write your code so that it only works if Assertions are turned on... and someone goes and turnst them off... You're in a world of hurt.
Check out these two articles in the JavaRanch Newsletter, hopefully they'll give you a better understanding of the correct usage of assertions:
Cindy's Segment - Asserting Yourself in Public by Cindy Glass
Assertions - Debugging in J2SE 1.4 by Thomas Paul
Enjoy!
[ August 15, 2003: Message edited by: Jessica Sant ]
 
Jui Mahajan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. That was good help
 
David Brafford
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also like
http://java.sun.com/j2se/1.4.1/docs/guide/lang/assert.html
http://www.fawcette.com/javapro/2002_11/online/assert_jstreet_11_14_02/
http://javaboutique.internet.com/tutorials/assertions/
- Dave
----------------
Considering the Certified Java Programmer Exam?
Get JCertify 7.0!
New integration with Beanshell
Integrated context sensitive explanations and content from
Eckel, Baldwin, and Green
http://www.enterprisedeveloper.com/jcertify
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic