Assert

  1. Definition
  2. During development, use an assert statement to disrupt normal execution if a boolean condition is false.


  3. Syntax

  4. assert(<expppression>)

    OR

    assert(<expppression>,<Optional Message>)


  5. Example

  6. 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

    void main() {

      var nb = 14;

      assert(nb > 10"You enter a number less than 10");

      print("Good Answer");

    }



    Good Answer