+ 17
Namita Arya Assertions are, primarily, a comfort to the user.
Because you can create your own error message to accompany an Assertion Error, the user often recieves a message that is more friendly to the average person (who has less programming or computer experience).
Furthermore, you can decide when an Assertion Error occurs - this is similar to a try/except process. However, Assertion Errors tend to be more user-friendly, while try/except is more often used for debugging.
+ 7
Assertions are used to raise an error if a condition is met.
This process may be used in debugging and testing, but mostly: because assertions can display an Assertion Error (that is created by the programmer) it is very useful when displaying information to the user, especially if they somehow used the program incorrectly.
Assertions can be thought of as an error report for the user, rather than an error report to the programmer or code itself.
+ 3
Sadaam Omer Ali -
As stated to Namita Arya:
"Assertions are, primarily, a comfort to the user.
Because you can create your own error message to accompany an Assertion Error, the user often recieves a message that is more friendly to the average person (who has less programming or computer experience).
Furthermore, you can decide when an Assertion Error occurs - this is similar to a try/except process. However, Assertion Errors tend to be more user-friendly, while try/except is more often used for debugging."
+ 1
Many confuse assertion with try/except because deep down, they both do the same thing. However, exceptions address the robustness of your application while assertions address its correctness.
Assertions should be used to check something that should never happen while an exception should be used to check something that might happen (something in which you don't have control like user input).
NOTE: The thumb rule is that use assertions when you are trying to catch your own errors and exceptions when trying to catch other people's errors.
0
It is an assertive answer
0
Oh thanks! I had the same question