This alternative is kinda cool, and allows specify...
# announcements
r
This alternative is kinda cool, and allows specifying multiple types:
Copy code
inline fun <T> tryOrNullWhen(vararg ignore: KClass<out Exception>, body: () -> T): T? =
  try { body() } catch (e: Exception) { if(ignore.any { it.java == e.javaClass }) null else throw e }
used like:
tryOrNullWhen(SomeException::class, SomeOtherException::class) { something() }