com.github.zhujk.resp.exception.RespException.kt Maven / Gradle / Ivy
package com.github.zhujk.resp.exception
class RespException(val code: Int, val msg: String) : RuntimeException(msg)
// guava
val Throwable.rootCause: Throwable
get() {
var throwable = this
// Keep a second pointer that slowly walks the causal chain. If the fast pointer ever catches
// the slower pointer, then there's a loop.
var slowPointer: Throwable? = throwable
var advanceSlowPointer = false
var cause: Throwable? = throwable.cause
while (cause != null) {
throwable = cause
if (throwable === slowPointer) {
throw IllegalArgumentException("Loop in causal chain detected.", throwable)
}
if (advanceSlowPointer) {
slowPointer = slowPointer?.cause
}
advanceSlowPointer = !advanceSlowPointer // only advance every other iteration
cause = throwable.cause
}
return throwable
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy