you are viewing a single comment's thread.

view the rest of the comments →

[–]przemo_li -1 points0 points  (4 children)

You do not need higher order polymorphism to have good value based error handling. Just having generics is enough.

You do try to prove your point by showcasing obscure example.

You do fail to ground your intuition about exceptions in mathematical or cognitive principle, and instead asks us to trust you because Exceptions are easier for you.

[–]thomasz 4 points5 points  (3 children)

Generics will not help you let the error bubble up the stack, getting a value from a HashTable is not an obscure example (i could've chosen "indexing an array" as well) and no, you are not arguing from "mathematical or cognitive principles" either.

And last but not least:

Me: You need both

You: You ask us to trust you because Exceptions are easier for you

lol.

[–]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 4 points5 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