Assert
- Definition
- Syntax
- Example
During development, use an assert statement to disrupt normal execution if a boolean condition is false.
assert(<expppression>)
assert(<expppression>,<Optional Message>)
void main() {
var nb = 6;
assert(nb > 10, "You enter a number less than 10");
print("Good Answer");
}
Unhandled exception:
'file:///C:/Users/marzo/Desktop/test/test.dart': Failed assertion: line 5 pos 10: 'nb > 10': You enter a number less than 10
'file:///C:/Users/marzo/Desktop/test/test.dart': Failed assertion: line 5 pos 10: 'nb > 10': You enter a number less than 10
void main() {
var nb = 14;
assert(nb > 10, "You enter a number less than 10");
print("Good Answer");
}
Good Answer