
org.jetbrains.kotlinx.jupyter.api.ThrowableRendering.kt Maven / Gradle / Ivy
package org.jetbrains.kotlinx.jupyter.api
import org.jetbrains.kotlinx.jupyter.util.isSubclassOfCatching
import kotlin.reflect.KClass
interface ThrowableRenderer {
fun accepts(throwable: Throwable): Boolean
fun render(throwable: Throwable): Any
}
class SubtypeThrowableRenderer(
private val superType: KClass,
private val renderer: (E) -> Any,
) : ThrowableRenderer {
override fun accepts(throwable: Throwable): Boolean {
return throwable::class.isSubclassOfCatching(superType)
}
override fun render(throwable: Throwable): Any {
@Suppress("UNCHECKED_CAST")
return renderer(throwable as E)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy