Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assertions

 
John Paterson
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am testing out 'assertions'. I seem to have some issues, following is the code:



I am expecting an assertion error to be thrown at the line: , but it's not happening and I don't understand why, hope somebody can help. Thanks.

regards
John
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must enable assertions with the JVM option -ea when running the program to see the error so use the command
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to explicitly run your programs with the assertion mechanism enabled, use the -ea or -enableassertions option of the java application launcher.
 
tro vial
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are assertions enabled in IDE's like netbeans and eclipse?

also, read a few things about assertions, but never really used them, are they really useful?
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tro vial wrote:are assertions enabled in IDE's like netbeans and eclipse?

also, read a few things about assertions, but never really used them, are they really useful?



as told by others assertions are disabled by default. even when you use ide's they are disabled. if you are using ide then you have to set the runtime parameter for enabling assertions. in case of netbeans, you can right click the project, then go to run and then in the textbox marked VM arguments you can enable them by writing -ea or -enableassertions and then run the project as you would normally do.

Yes assertions are really great for testing and debugging purposes. in my opinion they should be enabled by default.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have to start using batch files etc to start your applications in production? Assertions are a debugging tool, used to find situations that should never occur. During production you don't want them enabled. Therefore it's better to have them disabled by default, and enabled when you explicitly need it - during testing and debugging.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic