Assert
Last updated
Was this helpful?
Last updated
Was this helpful?
This is a very simple function that throws an AssertionError
typed error with a custom message when a condition is not met.
Since it throws an error, usage of assert
will halt execution of the current script.
This is the syntax for using assert
:
Let's assume you're creating a custom version of the class, adding a color
property, and you want to make sure the provided color is a valid hexadecimal number.
Use the assert
function to test the parameter's value against a regular expression, and provide a readable error message when the condition isn't met.