Empirically, Java tried it and programmers did everything in their power to squirm out from it
-
-
Yeah but I don't think that was a fault of typed errors, it was a fault of how their type system interacted with it. If an interface let implementors state what errors they could return, that would fix most of the issues. TBH I don't know how to make it work well with inheritance
1 reply 0 retweets 2 likes -
I think the biggest thing that Rust folks have zeroed in and agreed on is that typing is more important for libraries than applications. Libraries should return enums of their errors and give applications a chance to recover, apps usually just need a `Box<dyn Error>`
2 replies 1 retweet 3 likes -
Interesting, I would've expected the opposite. Libraries returning enums of their errors means they can never grow new errors without breaking clients
2 replies 0 retweets 0 likes -
You can mark an enum as non-exhaustive, which requires any `match`es outside the crate to have a default branch
1 reply 1 retweet 4 likes -
For errors that's pretty much always what you'd do anyway, since if consumers care about any of your error variants it's probably only only one or two
1 reply 0 retweets 1 like -
Nice, swift enums have the same functionality. However, at that point it seems to me the specific error type isn't doing much for your clients
3 replies 0 retweets 1 like -
Depends on the context. Diesel has an error variant for "this query was expected to return 1 or more rows, but zero were returned" for example which is commonly handled. Really the point is more than if your consumers can recover from a specific case, don't take the choice away
1 reply 1 retweet 4 likes -
It seems like you don't need API-specific typed errors to achieve that, though. You could have something where there's one Error type but APIs can provide a nonexhaustive set of subtypes they may produce, for documentation purposes
1 reply 0 retweets 0 likes -
Yeah, and that's roughly how the Error trait works in Rust actually. It's just not nearly as ergonomic as matching an enum
2 replies 0 retweets 3 likes
But that could easily be called a deficiency in the language and fixed with some new syntax for sure
-
-
Yeah, we allow pattern-matching an enum through the Error type in Swift. I feel like there could be a still better language feature for matching interesting errors, though…
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.