3 ms·
I use them a lot, for example in situations where I want to test why my code failed at a pre-check, so I can Unit Test its behavior better. Imagine a function t
by dep_b 1y ago
I use them a lot, for example in situations where I want to test why my code failed at a pre-check, so I can Unit Test its behavior better. Imagine a function that early returns for a variety of different reasons, and you want to test them to fail all.
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.