require function
Throws an exception if the specified requirement is not met.
Parameters:
requirement
: The boolean requirement to be checked.exception
: The exception message to be thrown if the requirement is not met.
Throws an exception with the specified message if the requirement is not met.
Example:
final value = 42;
require(value > 0, "Value must be greater than 0");
print("Value is valid: $value");
Implementation
require(bool requirement, String exception) {
if (!requirement) {
throw Exception(exception);
}
}