We would like to introduce an experimentalStrictlyPositiveInt.Companion.create for accepting a customized exception message.
fun StrictlyPositiveInt.Companion.create(
number: Number,
message: (Number) -> Any
): StrictlyPositiveInt
This function throws an IllegalArgumentException with the specified message if the specified number is less than or equals zero. If the message has a blank string representation, it throws the exception with a generic message instead.
Here are some examples of calling this function from Kotlin code:
println(StrictlyPositiveInt.create(1) { "$it should be greater than zero." }) // 1
StrictlyPositiveInt.create(0) { "$it should be greater than zero." } // throws an exception with the specified message
StrictlyPositiveInt.create(0) { " " } // throws an exception with a generic message
The StrictlyPositiveInt type being an inline value class, this function shouldn't be available yet for Java users.
📝 Description
We would like to introduce an experimental
StrictlyPositiveInt.Companion.create
for accepting a customized exception message.This function throws an
IllegalArgumentException
with the specifiedmessage
if the specifiednumber
is less than or equals zero. If themessage
has a blank string representation, it throws the exception with a generic message instead.Here are some examples of calling this function from Kotlin code:
The
StrictlyPositiveInt
type being an inline value class, this function shouldn't be available yet for Java users.✅ Checklist