nekoinemo
03/30/2017, 2:06 PMfun <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?