Second form of Assertion
The second for of assertion takes another expression as an argument.
The syntax is,
assert expression1 : expression2;
where expression1 is the condition and must evaluate to true at
runtime.
This statement is equivalent to
assert expression1 : throw new AssertionError(expression2);
Note: AssertionError is unchecked exception, because
it is inherited from Error class.
Here, expression2 must evaluate to some value.
By default AssertionError doesn’t provide useful message
so this form can be helpful to display some informative message
to the user.
|