2 ms·
> I would hate to have to reason about the 250 possible errors coming from every single library underneath my app That's is why I think exception are bad: the
by littlestymaar 6y ago
> I would hate to have to reason about the 250 possible errors coming from every single library underneath my app
That's is why I think exception are bad: the programmer usually ends up not thinking about the errors that can occur (and they often cannot even do it if they wanted because exceptions can come from anywhere) and just propagates to the user, who often doesn't even have access to the documentation of the underlying library, and must perform Google search on some cryptic error message, just to discover that the program is failing because some log formatting library he doesn't care about cannot have access to the configuration file it expected. This is a terrible user eperience.
And yes, checking 250 different kinds of error can be tedious (but it should never be so high anyway), but at least with sum types it's doable because the type system is here to help you cover every case. And then you can manually check which error is a reasonable one to return to your user and which is a recoverable one that should need no external intervention.
If the USB drive has been pulled out too quickly, just tell it to the user instead of returning a “aborted: did not have the rights to write to the file” exception.
- jcelerier 6y ago> and just propagates to the user, who often doesn't even have access to the documentation of the underlying library, and must perform Google search on some cryptic error message, just to discover that the program is failing because some log formatting library he doesn't care about cannot have access to the configuration file it expected. This is a terrible user eperience. you know what is even worse ? the programmer "handling" the error and just displaying a "we're sorry, an error has occured" message to the user who now has exactly zero way to know what is going wrong. Or as seems to be common in Rust, Go, and other exception-free systems, just calling panic! ... yay, "error handled". It is very irrealistic and presumptuous to assume that your program has enough domain knowledge about its users's systems to handle every single error.
- Ar-Curunir 6y agoYou don't have to handle those errors if you don't want to; you can just use `Box<dyn Error>` to propagate them without caring.
- littlestymaar 6y ago> you know what is even worse ? the programmer "handling" the error and just displaying a "we're sorry, an error has occured" message to the user This occurs a lot with language with exceptions too: you need to “handle” the exception before it reaches the root, otherwise it crashes the whole software (which is basically the same behavior than a panic in Rust or Go), so people usually add this kind of catch-all exception handling in Java or any language with exceptions. Have you ever encountered a “500 internal server error” while browsing so website? That's it. The main difference is that you can't do any better when using exception because you can't easily list all possible exceptions that can reach the root, while you can in languages with sum type. Of course there will be lazy programmers in any language, the problem with exception is that even if you aren't lazy, you cannot really do better than people who are (unless you can disable exceptions, like in C++ …).