| > Sounds like you hate exceptions, right? In which case why do you handle them at all? One of the problems with exceptions is it’s utterly impossible to know if a given function call can return exceptions and if so what they are. My code DOES want to handle errors. Exceptions are, imho, a very very poor way to report errors. Python is the bloody worst because I never effing know what the hell any damn function can throw or return. It’s so so frustrating. Error handling is a hard and unsolved problem. But I’ll take Rust results over exceptions 10,000% of the time. Not even a question. |
For example, you're implementing an arithmetic operator and have reached an erroneous state, but the arithmetic type doesn't have an error value, the only way to communicate the error is by throwing. Another example: you've specified that a function must always succeed, but later on you find a case where the function cannot succeed. Instead of fixing all the possible call sites, throw an exception. All those callers could not have handled the error anyway, because they were coded under the assumption that no error would happen at that point. Throwing an exception and letting it unwind the stack way up (perhaps even all the way up to main()) is the sensible solution, because at that point you've reached a situation with no reasonable way for that code to handle.
Saying that you prefer Result over exceptions is like saying that you prefer strings to functions. They do different things. If you like Result, nothing prevents you from implementing a C++ equivalent.