kotest-assertions / io.kotest.assertions.throwables / shouldNotThrowAny

shouldNotThrowAny

inline fun <T> shouldNotThrowAny(block: () -> T): T

Verifies that a block of code does NOT throw any Throwable

Use function to wrap a block of code that you want to make sure doesn't throw any Throwable.

Note that executing this code is no different to executing block itself, as any uncaught exception will be propagated up anyways.

Attention to assignment operations:

When doing an assignment to a variable, the code won't compile, because an assignment is not of type Any, as required by block. If you need to test that an assignment doesn't throw a Throwable, use shouldNotThrowAnyUnit or it's variations.

See Also

shouldNotThrowAnyUnit

shouldNotThrowExactly

shouldNotThrow