use
- During statement execution, insert assert(a bool expression) to determine exceptions.
- If the expression value is true, the following statement continues; If the value is false, an exception is reported.
- Assert takes effect only in debug mode and is ignored in production mode.
Such as:
int age = 22; assert(age>0); // Age itself should be greater than 0. If it is less than 0, an unusual error has occurred. print(age);Copy the code