When you have a typed throw that throws different errors for every edge case failing, even when an edge case failing is part of the expected behavior of the system, makes it much easier to reason about. Even when there is nothing happening towards the user or being logged.
Example:
Restore a user's session. It can fail because:
- Nothing was stored
- Something was stored, but it was in an outdated format
- Something was stored, but the token is expired
- Etcetera
It doesn't matter to the user, it's expected behavior, but at the same time they're different branches that all need to be covered.
extension String: Error { }
Because I like doing this: throw “Something went wrong”
Admittedly I don’t use this in shipping software.As for the feature: My “hot take” is: I’m skeptical this will really make software better and I suspect instead programmers will just spend more time designing error types and error handling than just creating software.