commonMain.com.bkahlert.kommons.exceptions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kommons-core-jvm Show documentation
Show all versions of kommons-core-jvm Show documentation
Kommons Core is a Kotlin Multiplatform Library that offers shared features for all Kommons modules.
package com.bkahlert.kommons
/**
* The root cause of this [Throwable], that is,
* the throwable that was thrown the first.
*/
public val Throwable.rootCause: Throwable
get() {
var rootCause: Throwable = this
while (rootCause.cause != null && rootCause.cause !== rootCause) {
rootCause = rootCause.cause ?: error("Must not happen.")
}
return rootCause
}
/**
* The causes of this [Throwable], that is,
* a list containing the [Throwable.cause], the cause of the cause, ...
*/
public val Throwable.causes: List
get() = when (val cause = cause) {
null -> emptyList()
else -> buildList {
add(cause)
addAll(cause.causes)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy