Zyle Moore
09/02/2021, 2:26 AMZyle Moore
09/02/2021, 2:32 AMNotANumber : Error()
and NoZeroReciprocal : Error()
for example. Or from the Error Handling Tutorial, it has the parent type as a CookingException
, despite it not being a subtype of Throwable or Exception.Zyle Moore
09/02/2021, 2:34 AMZyle Moore
09/02/2021, 2:35 AMZyle Moore
09/02/2021, 3:25 AMfail
the Test.
It looks something like
val kokiriForestDoor = Name("Kokiri Forest")
.map { Door(it) }
.getOrHandle { fail { "$it" } }
Is this (about) the right way to handle something like this?Patrick Louis
09/02/2021, 6:26 AMThe first question is: should these Error Sum Types subtype Exception or Throwable? If they don't subtype one of these, should we call them Errors instead of Exceptions?IMHO they should be completely separate from the `Exception`/`Throwable` hierarchy. If you need to capture a
Throwable
in one you can always create an alternate constructor for your sum type like
sealed class YourError {
data class SomeException(val e: Throwable) : YourError()
...
}
On the second part of your question I do also think that it is good to call the sum type something with Error, we usually call the top-most type DomainError
because it represents any error that might occur in the domain of the application.
You can however still give a name like SomeException single constructors if they are intended to hold an exception, like in my above example.simon.vergauwen
09/02/2021, 6:29 AMsimon.vergauwen
09/02/2021, 6:29 AMsimon.vergauwen
09/02/2021, 6:30 AM