Use of assert

1. Definition

  assert is a commonly used debugging method. To check Boolean expressions, a correct program must ensure that the value of the expression is true; if it is false, the program is in an incorrect state, and the assert will give a warning or exit.

 

Second, the format

  (1) assert [ boolean expression]

  • If [boolean expression] is true, the program continues to execute.
  • If it is false, the program throws AssertionError and terminates execution.

 

 

  (2) assert [ boolean expression: error expression (log)]

  • If [boolean expression] is true, the program continues to execute.
  • If false, the program throws java.lang.AssertionError and outputs [error message]

 

3. Open

The default assert (assert) in IDEA is off, set jvmthe parameters, the parameters are -enableassertionsor -ea(recommended).

 

Guess you like

Origin www.cnblogs.com/Tibbers/p/12708354.html