Skip to content

Files

Latest commit

 

History

History
31 lines (18 loc) · 717 Bytes

ObjectExtendsThrowable.md

File metadata and controls

31 lines (18 loc) · 717 Bytes

Pattern: Object extends Throwable

Issue: -

Description

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.

Example of incorrect code:

object InvalidCredentialsException : Throwable()

object BanException : Exception()

object AuthException : RuntimeException()

Example of correct code:

class InvalidCredentialsException : Throwable()

class BanException : Exception()

class AuthException : RuntimeException()

Further Reading