now i am learning assertions in java.
my doubt is what is the difference of assertions from an error
assert number < 0 : "Negative Number"
if (number < 0) throw(new Error("Negative Number"));
what is the difference between these two?
thanks in advance......
In the case where number>=0, the assert version will only result in an error if assertions are enabled at runtime. In that case it will be an instance of AssertionError.
Assertions were described as part of the 1.4.2 documentation guide in the section Programming with Assertions.