Hi, I’m brand new to Kotlin and have started out by converting a Java class in a small project to a Kotlin file. This has caused this issue regarding checked exceptions in the Java consumer code. I tried the documented solution using the @Throws annotation, but this breaks the Kotlin code with the error “This annotation is not applicable to target ‘initializer’”. The @Throws annotation seems to work correctly when attached to functions, but not to the init block. Any advice on how to overcome this would be much appreciated.
So I worked this out after doing some more reading of the docs; the trick was to delete the init block and create an explicit secondary constructor, which accepted the @Throws annotation. The Java code now compiles and catches the right exception when thrown by the Kotlin secondary constructor.