异常处理

class Car

class Seller {
    private var cars = arrayOf<Car>()

    fun sell() {
        if (!cars.any()) {
            throw Exception("No cars for sale")
        }
    }
}

val seller = Seller()
try {
    seller.sell() //<-Error 
}
catch (e: Exception) {
    println(e.message)
    //e.message is "No cars for sale"
}