Hi, my proposal is to have something to tell the `...
# language-proposals
l
Hi, my proposal is to have something to tell the
when
expression to fail if no case matches, in a syntax similar to
!!
for non null assertions. Currently, I have to add a
else
case and throw an
IllegalArgumentException
or an
IllegalStateException
, which adds a line for each when clause, which is quite a lot for 2-3 cases when expressions. How about a syntax like the following?
Copy code
val message: String = when!! {
    code == 0 -> "Ok"
    result.failed -> "Some error ;)"
}
Copy code
val text: String = when(number)!! {
    0 -> "Zero"
    1 -> "One"
}