package bhylu.lessons.k_exceptions fun parseMinutes(raw: String): Int { val minutes = raw.toIntOrNull() ?: throw IllegalArgumentException("Need whole minutes") require(minutes in 1..240) { "Minutes must be 1..240" } return minutes } fun main() { for (text in listOf("30", "-1", "bad")) { val notice = try { "Minutes: " + parseMinutes(text) } catch (error: IllegalArgumentException) { "Invalid duration" } println(notice) } }