Leverage the assert statement to verify the validity of expressions:
public
class |
The assert keyword checks a boolean expression and throws an AssertionError if the expression evaluates to false. When this exception is thrown, it indicates that the assertion has failed.
You can add an optional expression to serve as the exception message if the assertion fails.
By default, assertions are disabled, and assert statements are ignored unless assertions are explicitly enabled.
The purpose of assertions is to clearly indicate where a program behaves unexpectedly during debugging and testing.