简体   繁体   中英

How to enable assertions in dart?

here is an excerpt from my code containing the assertion

assert(age<30,'age must be less than 30');                             

Now, How to enable this assertion?

Use the --enable-asserts flag:

dart --enable-asserts file_name.dart

assert s are enabled in debug builds of Flutter apps. They are not enabled in release builds.

If you need to check conditions in release builds, assert s are inappropriate: assert s are intended as sanity-checks to identify logical errors (ie, mistakes in the code), not to catch runtime errors (eg unexpected input from the users).

Also see: why the assert function was disabled in dart?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM