Member-only story
Why exceptions are still ok
Exceptions are nice. It’s an elegant concept to signal that something went not as planned and handle it separately from the main logic. However, some people claim that exceptions are an anti-pattern and shouldn’t be used, and we’ve looked at the arguments to support that point of view. However, what wasn’t considered is what good things we have when using exceptions: maybe the benefits outweigh the costs?
Arguments against
The previous article lists the following difficulties with exceptions:
- Use of exceptions allowed to postpone error handling, and oftentimes with pressure to deliver features it’s not addressed until it is discovered by end-user
- Exceptions perform a one-way transfer to another line of code making it not obvious how would execution go just by looking at function code.
- Sometimes exceptions are used instead of return values, which hurts readability and obscures API
- Lots of decision have to be made upfront to use exceptions consistently across the project
Essentially there is no question that exceptions are a convenient tool, but there are concerns about the costs of using it in the long run, when most of our time is spent updating existing code, not writing a new one. Let’s walk over each argument and see if there is a…