It is very useful to check our assumptions. Statements constantly check whether the invariant is true. In short, it is used for the following purposes:
- This allows you to implement a fault tolerant system.
- It reduces the spread of errors due to side effects.
- It prohibits (a kind of health check) the system to enter an inconsistent state due to user data or subsequent code changes.
Sometimes I prefer to use assert_return () when we don't want to use try / catch / throw.
private void WriteMessage(string message) { assert_return(message != null, "message is null"); // return when false File.WriteAllText(FILE_PATH, message); }
I suggest assert_return () to stop the application by reporting an error in the test build. And then in the production system, it must register and register and return from the function, saying that it cannot do this.
shuva
source share