``` fun <T : RuntimeException> shouldThrow(t...
# getting-started
n
Copy code
fun <T : RuntimeException> shouldThrow(type: Class<T>, block: () -> Unit) {
    try {
        block()
    } catch (e: T) {
        return
    } catch (e: Exception) {
        throw IllegalStateException("Thrown unexpected exception ${e::class.java.canonicalName}")
    }

    throw IllegalStateException("Didn't throw exception")
}

class GLException : java.lang.RuntimeException()

fun test(){
    shouldThrow(GLException::class.java){
        //throwing code
    }
}
Seem to work for me, can you check?