I spent this week on refactoring my code of past three months. It’s a torturous work. And the one which makes me want to tear my hair out, is Exception-Handing. I luckily followed almost all the Not-To-Do listed in <Exception-Handling Antipatterns> .
Actually Exception-Handling design have great influence on total quality.Bad Exception-Handling sometime ruin good design. I list here some guideline mentioned in <Toward Exception-Handling Best Practices and Patterns> .Make it right even if it goes wrong.
- Don’t try to handle coding errors.
- Avoid declaring lots of exception classes.
- Name an exception after what went wrong, not who raised it.
- Recast lower-level exceptions to higher-level ones whenever you raise an abstraction level.
- Provide context along with an exception.
- Handle exceptions as close to the problem as you can.
- Assign exception-handling responsibilities to objects that can make decisions.
- Use exceptions only to signal emergencies.
- Don’t repeatedly rethrow the same exception.