DEV Community

Cover image for Dart Assert Keyword
Gülsen Keskin
Gülsen Keskin

Posted on • Edited on

1

Dart Assert Keyword

assert

"assert" operatörü, Dart dilinde bir koşulun doğru olduğunu test etmek için kullanılır. Eğer koşul doğru değilse, bir "AssertionError" atar ve kodun çalışması durur. "assert" operatörü, genellikle test ve debug amaçlı kullanılır ve çalışma zamanında kapatılabilir.

Kullanımı şöyledir:

assert(x > 0);
Enter fullscreen mode Exit fullscreen mode

Bu örnekte, "x" değişkeninin sıfırdan büyük olduğu koşulu test edilir. Eğer koşul doğru değilse, bir "AssertionError" atılır ve kodun çalışması durdurulur.

"assert" operatörü, ayrıca bir ikinci argüman olarak bir mesaj verilebilir. Bu mesaj, eğer koşul doğru değilse hata mesajı olarak kullanılır. Örnek:

assert(x > 0, 'x değeri sıfırdan büyük olmalıdır');

Enter fullscreen mode Exit fullscreen mode

Bu örnekte, eğer "x" değişkeni sıfırdan büyük değilse, hata mesajı olarak "x değeri sıfırdan büyük olmalıdır" gösterilir. "x" değişkeni 0 dan büyükse, iddia başarılı olur ve yürütme devam eder.

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

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs