orThrow
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)
Content copied to clipboard
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);
Content copied to clipboard
See the orNull method for returning null
instead of throwing an exception in case of invalid number.