0
fun fun1(id: String)
{
    addThings(3,4)
}

fun addThings(num1: Int, num2: Int)
{
    addNumbers(num1, num2)
}

@Throws(Exception::class)
fun addNumbers(num1: Int, num2: Int)
{
   throws Exception("error")
}
  1. Excption from addNumbers will bubble up all the way to fun1 is that right?
  2. Is @Throws required for addThings and fun1?

Couldn't find any docs online...

1 Answer 1

3

No.

You can find good documentation on this here.

In summary, Kotlin does not have checked exceptions. That means there is no "bubble up". There is no requirement for any of your functions to declare that they throw an exception or to use try-catch. Declaring the annotation @Throws is only strictly necessary for Java interop, you may need it if you call that Kotlin function from a Java file.

You can read about why from Kotlin's project lead Roman Elizarov.

Sign up to request clarification or add additional context in comments.

1 Comment

It’s not necessary for Java interop. It’s optional. Declaring it causes it to enforce it as a checked exception.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.