I like to indicate that a function might throw an exception. Currently, I have a few validation functions in the form of:
val throwUnlessX: String => Unit = (foo: String) => {
if (foo != "bar") {
throw new Throwable("Poit!")
}
}
It's typed with Unit
as a return type, yet strictly speaking that's not entirely correct as the function may also never return as it may throw an exception instead.
Other languages have the concept of defining a never
type, either for infinite loops or said exception throwing.
Is there something I can do to indicate to a developer that a function might throw or never returns?