klyn.unittest.Assert.assertThrows
method
public static assertThrows<TYPE extends Exception = Exception, RESULT = Void>(notnull block as () -> RESULT) as Void
Description

Verifies that invoking a function or lambda without parameters raises an exception.

When TYPE is omitted, any exception type is accepted. When TYPE is provided, the raised exception must match it. The callable's return type RESULT is inferred; its result is ignored. An evaluated expression is not a callable and is rejected at compilation.

Parameters
ParameterDescription
blockThe parameterless function or lambda to invoke once.
Throws
  • AssertionError If no exception is raised or its type does not match TYPE.
Example
import klyn.unittest

Assert.assertThrows(lambda (): Int("abc"))
invalidCodeUnit = -1
Assert.assertThrows<TypeError>(lambda (): CodeUnit(invalidCodeUnit))