To add to miensol's answer: although multi-catch in Kotlin isn't yet supported, there are more alternatives that should be mentioned.
Aside from the try-catch-when, you could also implement a method to mimic a multi-catch. Here's one option:
fun (() -> Unit).catch(vararg exceptions: KClass<out Throwable>, catchBlock: (Throwable) -> Unit) { try { this() } catch (e: Throwable) { if (e::class in exceptions) catchBlock(e) else throw e } }
And using it would look like:
fun main(args: Array<String>) { // ... { println("Hello") // some code that could throw an exception }.catch(IOException::class, IllegalAccessException::class) { // Handle the exception } }
You'll want to use a function to produce a lambda rather than using a raw lambda as shown above (otherwise you'll run into "MANY_LAMBDA_EXPRESSION_ARGUMENTS" and other issues pretty quickly). Something like fun attempt(block: () -> Unit) = block would work.
Of course, you may want to chain objects instead of lambdas for composing your logic more elegantly or to behave differently than a plain old try-catch.
I would only recommend using this approach over miensol's if you are adding some specialization. For simple multi-catch uses, a when expression is the simplest solution.