What's the recommended way in Dart: asserts or throw Errors

前端 未结 4 921
攒了一身酷
攒了一身酷 2021-01-11 16:25

Dart explicitly makes a distinction between Error, that signals a problem in your code\'s logic and should never happen and should never be caught and Exceptions that signal

4条回答
  •  盖世英雄少女心
    2021-01-11 17:00

    When exactly do assertions work? That depends on the tools and framework you’re using:

    Flutter enables assertions in debug mode.
    Development-only tools such as dartdevc typically enable assertions by default.
    Some tools, such as dart and dart2js, support assertions through a command-line flag: --enable-asserts.
    In production code, assertions are ignored, and the arguments to assert aren’t evaluated.

    Refer:https://dart.dev/guides/language/language-tour#assert

提交回复
热议问题