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

前端 未结 4 884
攒了一身酷
攒了一身酷 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 16:48

    As asserts are ignored in production mode, you should use them as way to do initial tests to your code logic in debug mode:

    In production code, assertions are ignored, and the arguments to assert aren’t evaluated.

提交回复
热议问题