Обработка исключений

class IsNullExceptionException()
class IsEmptyExceptionException()

fun throwWhenNullOrEmpty(list: Array<Int>?) {
    if (list == null) {
        throw IsNullException()
    }
    if (!list.any()) {
        throw IsEmptyException()
    }
}

try {
    val list = arrayOf<Int>()
    throwWhenNullOrEmpty(list)
}
catch(e: IsNullException) {
    println("list is not specified")
}
catch(e: IsEmptyException) {
    println("list is empty")
}