4

In general case I can use if(value), == ,!= and so on operation, then when and why should I use assert?

1
  • See en.wikipedia.org/wiki/Fail-fast. Using asserts to abnormally end a program is a means of failing quickly and loudly rather than gracefully accepting malformed input data ( for example ). Commented Oct 20, 2015 at 3:49

1 Answer 1

0

You can use assert in tests. In case of failure it will generate an exception, which is perfect for your test framework to detect that something went wrong.

You generally don't want to use assert outside of tests as it will generate exceptions that you need to catch, while an error message/code is simpler to handle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.