Leon K
12/05/2019, 4:40 PMrequire
that allow for specifying a custom Exception type to throw, instead of just throwing IllegalArgumentException
karelpeeters
12/05/2019, 4:47 PMif
.Leon K
12/05/2019, 6:42 PMif(foo == null) throw Foo()
and smart-cast foo into non-null by thatLeon K
12/05/2019, 6:43 PMrequire
LeoColman
12/05/2019, 8:40 PMrequire
, with the same contractsLeoColman
12/05/2019, 8:40 PMIllegalArgumentException
. Other use cases are on a per-user basiskarelpeeters
12/05/2019, 9:22 PMLeon K
12/06/2019, 4:10 PMkarelpeeters
12/06/2019, 4:10 PMLeon K
12/06/2019, 4:10 PMLeon K
12/06/2019, 4:11 PMkarelpeeters
12/06/2019, 4:15 PMrequireThrow(i > 0) { MyException("foo") }
instead of
if (i <= 0) throw MyException("foo")
? That's not even shorter!karelpeeters
12/06/2019, 4:16 PMLeon K
12/06/2019, 4:25 PMif
here is that it isn't as expressive, thus not as readable.
when seeing
if (verrryLongConditionThatChecksSomeData) {
throw FooException("bar")
}
you don't immediately know that this is just validation-logic. its not bad, but it could very well be better.
being short doesn't mean readable. Expressive within a given context means readable ;D