4 ms·
Exceptions are just a way for a piece of code to say to its callers: "Sorry guys, this is over my head, I give up, sort this one yourselves." And since most pie
by Mikhail_Edoshin 11y ago
Exceptions are just a way for a piece of code to say to its callers: "Sorry guys, this is over my head, I give up, sort this one yourselves." And since most pieces are pretty simple, they encounter these situations routinely. Now, if you want things like nice syntax you positively need exceptions at least as a concept. Otherwise you cannot even add two numbers: take `a + b`, what if the result overflows? What if you write `x = foo(y, bar(z))` and `bar()` fails to deliver? Maybe the try/throw/catch syntax is not that convenient, or maybe the documentation doesn't list all the exceptions that may arise and you feel out of control, or maybe a particular implementation is slow; these are all valid reasons. But I don't see how you can get rid of the idea of exceptions. Well, maybe functional languages have something here, but I'm not an expert in this area; my understanding is that you may define a function as returning either `Error` or `UsefulResult` so you can branch accordingly.