This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

John Paterson
Ranch Hand

Joined: Mar 12, 2012
Posts: 81
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
Ranch Hand

Joined: Mar 17, 2012
Posts: 220
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: 1409

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: 868

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.


OCPJP 6(100 %) OCEWCD 6(91 %)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

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
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Assertions
 
Similar Threads
Assertions
Assertion doubt
dan exam doubt 12
java Exceptions
Assertion Q