https://kotlinlang.org logo
#announcements
Title
# announcements
d

diesieben07

09/03/2017, 12:14 PM
Yeah, I know those already. But neither
requireXXX
(for "check incoming arguments") nor
checkXXX
(for "check if this method may be called right now") are appropriate for an "this internal state must be like this or I made a programmer error".
a

arekolek

09/04/2017, 2:05 PM
Why isn’t
checkXXX
appropriate in your opinion? It throws an
IllegalStateException
, and if you look at the samples https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/samples/test/samples/misc/preconditions.kt they use it to check state.
d

diesieben07

09/04/2017, 6:29 PM
If you read the Javadocs on
IllegalStateException
it becomes clear:
Signals that a method has been invoked at an illegal or inappropriate time.
That is not the case, it was fine to invoke the method here, but something inside the method went wrong, due to a program bug.