assertFailsWith

Common
JVM
JS
Native
1.0
inline fun <reified T : Throwable> assertFailsWith(
    message: String? = null,
    noinline block: () -> Unit
): T

Asserts that a block fails with a specific exception of type T being thrown.

If the assertion fails, the specified message is used unless it is null as a prefix for the failure message.

Return An exception of the expected exception type T that successfully caught. The returned exception can be inspected further, for example by asserting its property values.

Common
JVM
JS
Native
1.0
fun <T : Throwable> assertFailsWith(
    exceptionClass: KClass<T>,
    block: () -> Unit
): T

Asserts that a block fails with a specific exception of type exceptionClass being thrown.

Return An exception of the expected exception type T that successfully caught. The returned exception can be inspected further, for example by asserting its property values.

Common
JVM
JS
Native
1.0
fun <T : Throwable> assertFailsWith(
    exceptionClass: KClass<T>,
    message: String?,
    block: () -> Unit
): T

Asserts that a block fails with a specific exception of type exceptionClass being thrown.

If the assertion fails, the specified message is used unless it is null as a prefix for the failure message.

Return An exception of the expected exception type T that successfully caught. The returned exception can be inspected further, for example by asserting its property values.