In general case I can use if(value), == ,!= and so on operation, then when and why should I use assert?
-
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 ).Erik– Erik2015-10-20 03:49:32 +00:00Commented Oct 20, 2015 at 3:49
Add a comment
|
1 Answer
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.