aspose file tools*
The moose likes Java in General and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 121
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

Joined: Mar 17, 2012
Posts: 892
    
    9
You must enable assertions with the JVM option -ea when running the program to see the error so use the command
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1761
    
    7

You need to explicitly run your programs with the assertion mechanism enabled, use the -ea or -enableassertions option of the java application launcher.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
tro vial
Greenhorn

Joined: May 22, 2012
Posts: 17
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

Joined: Apr 04, 2012
Posts: 924
    
    1

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

Joined: Oct 27, 2005
Posts: 19672
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertions