error

Throws an IllegalStateException with the given message.

inline fun error(message: Any): Nothing(source)
fun validateAge(age: Int) {
    if (age < 0) error("Age cannot be negative: $age")
}

fun main() {
    try {
        validateAge(-5)
    } catch (e: IllegalStateException) {
        println(e.message) // Prints: Age cannot be negative: -5
    }
}

Source