How can I throw a custom exception in Kotlin?

Solution

If you want to create a custom Exception, just extend Exception class like:

class CustomException(message: String) : Exception(message)

fun main(args: Array<String>) {
    throw CustomException("Error!")            // Throw Exception in thread "main"
}             
Tagged: