Hi all! I’m a Swift programmer, and in Swift there seems to be a common programming pattern for creating and throwing custom exceptions using an enum. For instance, if I’m writing a calculator app, it would go something like this:
enum CalculatorError: Error {
case inputError(message: String)
case invalidNumber(number: Int)
case nilInput
//...
}
class Calculator {
func calculate(input: String) throws {
//...
throw CalculatorError.inputError(message: "This input is invalid!")
}
}
Have you guys ever seen a pattern for custom exceptions show up in Kotlin? Maybe using data classes, maybe using sealed classes… I’m not really looking for a translation of this Swift code, rather I want something really Kotlin-y. I’d love to hear your thoughts