Hi, is there a given pattern on when (and when not...
# announcements
n
Hi, is there a given pattern on when (and when not) to use
check
functions? We have a use-case where we'd like to throw a concrete custom Exception. What would be the ideal way to do it? Wrap it later, but use
check
Copy code
try {
  check(<exp>){ "check failed"}
}  catch(e: IllegalStateException) {
  throw CustomException(e)
}
or throw it directly,
Copy code
if (<exp>) {
  throw CustomException("check failed)
}
d
Throwing it directly. There is no advantage in throwing the IllegalStateException first, catching it and then throwing another one. You should use check to validate the state of the object.
👍 1
v
You can also make an own top-level function like
check
that throws the exception you want if you prefer the syntax of
check
instead of an
if
with
throw