2015-08-24 16 views

Odpowiedz

4

Od Dart 1.22, assert() trwa opcjonalną wiadomość.

assert(configFile != null, "Tool config missing."); 

Jeśli twierdzenie nie powiedzie, będzie produkować coś jak następuje:

Unhandled exception: 
'file:///.../main.dart': Failed assertion: line 9 pos 10: 
'configFile != null': Tool config missing. 
#0  _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:33) 
#1  _AssertionError._throwNew (dart:core-patch/errors_patch.dart:29) 
#2  main (file:///.../main.dart:9:10) 

Zauważ, że komunikat o błędzie zawiera rzeczywiste twierdzenie (configFile != null).

4

Jest kwestią otwartą z obejścia https://github.com/dart-lang/sdk/issues/6190#issuecomment-119103626

assert(() => test || throw "message"); 

próbowałem tego, ale ten sposób nie działa. Nieco zmodyfikowana wersja pracy

var test = false; 
assert(test ? true : throw "message"); 

Zobacz także

Powiązane problemy