Why Assertions Is Used?
Assertions Are Used to Codify the Requirements That Render a Program Correct or Not by Testing Conditions (Boolean Expressions) for True Values, and Notifying...
Assertions are used to codify the requirements that render a program correct or not by testing conditions (Boolean expressions) for true values, and notifying the developer when such conditions are false. Using assertions can greatly increase your confidence in the correctness of your code.
What are assertions and why do we use them?
Assertion are boolean expressions which should typically always be true. They are used to ensure what you expected is also what happens. You wrote the function to deal with ages, you also 'know' for sure you're always passing sensible arguments, then you use an assert.
Where can we use assertions?
Assertion Vs Normal Exception Handling
Assertions are mainly used to check logically impossible situations. For example, they can be used to check the state a code expects before it starts running or state after it finishes running. Unlike normal exception/error handling, assertions are generally disabled at run-time.