All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlinx.jupyter.api.ThrowableRendering.kt Maven / Gradle / Ivy

There is a newer version: 0.12.0-335
Show newest version
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 - 2024 Weber Informatics LLC | Privacy Policy