aspose file tools*
The moose likes IDEs, Version Control and other tools 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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

podonga poron
Ranch Hand

Joined: May 12, 2008
Posts: 55
I am reading a book who tells if i do an assertion and the assertion is NOT true, the program stop executing and an error (AssertionError) is throw ..

is this correct ?

because when i tryed in NetBeans ..

int a = 8;
assert(a==2); NOTHING HAPPEN

how this work ?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Podonga,
Do you have assertions enabled? If assertions are not enabled, they don't do anything.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
podonga poron
Ranch Hand

Joined: May 12, 2008
Posts: 55
i think they are not enabled

do you know how to enable in netbeans ? i need to practice ... and compiling using javac -ea every time is tedious !
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

You don't compile using the -ea flag, you run it using the -ea flag. The assertions are compiled into the code regardless of the flags.

Isn't there a way to tell NetBeans to run your code with assertions enabled?

As a side node, you do know that your code should work just the same with and without assertions enabled? You can't assume that somebody else will also have assertions enabled when he/she runs your code.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

I'm going to move this to our IDEs forum where people know more about NetBeans.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

I think you forgot the actual moving part
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Originally posted by Rob Prime:
I think you forgot the actual moving part

Sorry. The phone rang and then I forgot about it
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Assertions