Join
Blogs
Questions
Videos
Tags
Members
Search
 
 
Create your own blog, earn points and get popular!

Second Form of Assertion

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.


This brings us the end of Java Assertion Tutorial. Please let us know your views by leaving the comment in the comments section below.


<< Enable or Disable Assertion
No votes yet
Share this

Post new comment