aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regarding assertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regarding assertion" Watch "Regarding assertion" New topic
Author

Regarding assertion

Suguna Gollapally
Ranch Hand

Joined: Oct 31, 2006
Posts: 37
public class Test {

private Boolean isValid(int i) {

if(i<1 || i>12)
return new Boolean("Incorrect value");

else
return new Boolean(true);
}

private void testValue(int val) {

assert isValid(val) : "Out of range";
}
public void static main(String s[]) {

Test t=new Test();
t.testValue(22);
}
}

why is this prog doesn't throw assertion error even though assert(isValid) is not true
Loveen Jain
Ranch Hand

Joined: Jan 24, 2004
Posts: 35
Are you sure you turned on the assertions while running the program.

Try this:
java -ea <class-name>

I tried to run this code and got the following Exception

Exception in thread "main" java.lang.AssertionError: Out of range
at com.javaranch.AssertTest.testValue(AssertTest.java:13)
at com.javaranch.AssertTest.main(AssertTest.java:17)
Suguna Gollapally
Ranch Hand

Joined: Oct 31, 2006
Posts: 37
Thanks jain..

Even i got the same output when i enabled the assertions..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding assertion