Tomas Votruba has a post to his site sharing his top seven tips for writing exceptions that "everyone will love" and how they could be considered a more than just a programming tool.
Do you ever had that feeling, that you've seen that exception before and you know what it means and how to solve? What if that would be clear even for those who see it for the first time? It would save yours and their time.Exceptions are not just error state. Exceptions are the new documentation.
He starts off by describing a situation just about any developer would be familiar with, the "circle" where an exception is thrown when something breaks and there's no additional information so you're back to where you started. Based on his work in the EasyCodingStandard
he's come up with seven tips to help prevent this in your applications:
- Make Exception Names for Humans
- Use " around" Statements
- What Exactly is Wrong?
- What is The Wrong Value?
- What File Exactly is Broken?
- What Options do I have?
- Link what You can't Fit 140 Chars
For each item on the list there's code snippets illustrating the suggestion and a brief description for more context.