Throwable and Error should not be caught in Kotlin (equivalent of Java rule: squid:S1181)


The rule squid:S1181 (“Throwable and Error should not be caught”) is true in Kotlin as well.

Please add that rule for Kotlin.

Actually many of the Java rules also apply to Kotlin, because both target the same platform: Java (Yes, Kotlin may target JS, or Native, but Kotlin’s design is made mainly with the Java platform in mind).

It would be nice to review the Java rules, and create a Kotlin equivalent for each of them which also apply to Kotlin.

I think it is quite important, because most of the people introduce Kotlin in existing code-base by converting existing Java classes. Then issues may suddenly disappear in sonar, just because the code has been converted to Kotlin, although the problems are still here.


As you might know Kotlin analyzer is implemented on the top of the Slang library. That means that we have a set of rules running on several languages (incl. Kotlin, Ruby, Scala). That means that these rules should be generic enough to be applicable to many languages and implementable on top of universal AST. We are considering writing language-specific rules, but I’m afraid this year Kotlin is not our priority and we will not invest there. FYI there is an ability to import external issues for Kotlin, may be it will allow you to fill the gap you feel.