Complete the code to define a custom exception class named MyException.
class MyException : [1]("Custom error occurred")
The custom exception class should inherit from Exception, the standard base class for custom exceptions in Kotlin.
Complete the code to throw the custom exception MyException.
fun checkValue(value: Int) {
if (value < 0) {
[1] MyException()
}
}In Kotlin, you use throw to throw exceptions.
Fix the error in the custom exception class constructor to accept a message parameter.
class MyException(message: String) : Exception([1]) {}
The constructor parameter message should be passed directly to the base Exception class.
Fill both blanks to create a custom exception with a default message and a secondary constructor.
class MyException : Exception { constructor() : super([1]) constructor(message: String) : super([2]) }
The default constructor passes a fixed string, and the secondary constructor passes the message parameter.
Fill all three blanks to create a custom exception class with a message property and override the toString method.
class MyException(val [1]: String) : Exception([2]) { override fun toString(): String { return "MyException: " + [3] } }
The property and constructor parameter are named message, and the toString method returns it.