org.jetbrains.kotlinx.jupyter.api.ThrowableRendering.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-api Show documentation
Show all versions of kotlin-jupyter-api Show documentation
API for libraries supporting Kotlin Jupyter notebooks
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)
}
}