Throw Exceptions

Could something like a default error be defined i.e

@Throws(IOException::class)
fun readFile(name: String): String {
     throw "Can not read file"
}

translated to

@Throws(IOException::class)
fun readFile(name: String): String {
     throw IOException("Can not read file")
}

not default exactly but since we have already informed the compiler to expect an exception in the defined function why not have the throw by default initialize that error type
thus in the function

@Throws(IOException::class)
fun readFile(name: String): String {
      if(true){
            // section not affected by compiler as error initializer is defined
            throw Error(message)
      }else {
            // section affected by the compiler as the error was defined by the annotation @Throws
           // throwing IOException
            throw message2
     }
}

@brymher your sample is harder to understand for me (a human).

You have to handle also case like: @Throws(AnException::class, OtherException::class). What should be the expected behavior?

Finally you have to consider corner case like: class Crash(cause: Throwable) : Throwable(cause), in such case throw Error(message) create an Error or a Crash?

@Throws annotation is provided only for Java compatibility, it does not affect the language, but the compiler only.