KT.OBJECT_EXTENDS_THROWABLE

Object that extend any type of Throwable

This rule reports all objects including companion objects that extend any type of Throwable. Throwable instances are not intended for reuse as they are stateful and contain mutable information about a specific exception or error. Hence, global singleton Throwables should be avoided. See https://kotlinlang.org/docs/object-declarations.html#object-declarations-overview See https://kotlinlang.org/docs/object-declarations.html#companion-objects

Noncompliant Code

Copy
object InvalidCredentialsException : Throwable()

object BanException : Exception()

object AuthException : RuntimeException()

Compliant Code

Copy
class InvalidCredentialsException : Throwable()

class BanException : Exception()

class AuthException : RuntimeException()

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html