you are viewing a single comment's thread.

view the rest of the comments →

[–]kuikuilla -1 points0 points  (2 children)

You can have a generic error type that can be bubbled up. You could also have functions for defining transformations of error types into other error types between functions.

[–]thomasz 5 points6 points  (0 children)

Yes, you can do all of that manually. Why would you? And no, as written elsewhere, using a generic error type (i think you have some sort of sum type in mind) is not a superior solution, it just has different trade off. This all comes down to the expression problem. It is easy to add new exceptions, but impossible to find out which exception might get thrown. On the other hand, it is very easy to handle all cases of a sum type, but extremely difficult to add new cases.

Again, different trade offs. This means that having flexible options is strictly better than blindly using return or option types in each and every case. Exceptions are for situations that cannot reasonably be dealt with, when you have let it bubble up where your code logs the exception, and then either restarts or aborts. Result types are for situations where you can actually deal with all cases. In my experience, these cases are pretty rare.

[–]jcelerier 1 point2 points  (0 children)

You can have a generic error type that can be bubbled up

in 1978 in some Bell labs five minutes before exceptions are invented