Skip to content

Instantly share code, notes, and snippets.

@optimho
Created January 8, 2022 20:55
Show Gist options
  • Select an option

  • Save optimho/527f3090dc4a3f6994788c54174286fd to your computer and use it in GitHub Desktop.

Select an option

Save optimho/527f3090dc4a3f6994788c54174286fd to your computer and use it in GitHub Desktop.
Create and throw an exception
import java.time.temporal.TemporalAmount
import kotlin.reflect.typeOf
fun main(args: Array<String>) {
val p:Person = Person("Michael", 10)
if (p.age<12){
throw InvalidAgeException(p.age, "WTF dude")
}
}
class InvalidAgeException(val age: Int, override val message: String): IllegalArgumentException("Invalid Age: $age, $message"){}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment