orThrow

@ExperimentalSince(version = KotoolsTypesVersion.V4_5_3)
fun orThrow(number: Byte): Zero

Creates an instance of Zero from the specified number, or throws an IllegalArgumentException if the number is other than zero.


Calling from Kotlin

Here's an example of calling this method from Kotlin code:

val number: Byte = 0
val isSuccess: Boolean = try {
Zero.orThrow(number)
true
} catch (exception: IllegalArgumentException) {
false
}
assertTrue(isSuccess)

Calling from Java

Here's an example of calling this method from Java code:

final byte number = 0;
boolean isSuccess;
try {
Zero.orThrow(number);
isSuccess = true;
} catch (final IllegalArgumentException exception) {
isSuccess = false;
}
Assertions.assertTrue(isSuccess);

See the orNull method for returning null instead of throwing an exception in case of invalid number.