|
|
|
|
|
by absove
1641 days ago
|
|
Not so much a nitpick because with checked exceptions your method signature can declare multiple types of exception whereas Result generalizes your specific exceptions to Throwable, which you can't pattern match with the compiler being able to enforce exhaustiveness. So to achieve the same exhaustiveness as a method like User createUser() throws IOException, BusinessException you would need both a Result-like construct and union types Either<User, IOException | BusinessException> createuser() which few mainstream languages offer.
Otherwise you type is unable to express that only IOException and BusinessException are thrown and you don't need to handle a default Throwable case. |
|
methods that declare checked exception can throw RuntimeException(s) so exhaustiveness cannot be totally enforced anyway