| 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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
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: 19216
|
|
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
How To Ask Questions How To Answer Questions
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
|
I'm going to move this to our IDEs forum where people know more about NetBeans.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
I think you forgot the actual moving part
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26168
|
|
Originally posted by Rob Prime: I think you forgot the actual moving part
Sorry. The phone rang and then I forgot about it
|
 |
 |
|
|
subject: Assertions
|
|
|