- Avoid throwing an exception whenever possible. In stead return special values e.g. null.
- Throw early, catch later
- Either throw an exception or log them but never do both
- Always throw a checked exception, unless it’s a severe error that cannot be handled by the caller of the api.
- Maintain layer wise clear abstraction on errors and exceptions so that even if there is a change in the lower layer, consuming layers should not be affected. A particular exception from one layer should never be carried onto the next layer.
March 10, 2009
5 Tips for Error Handling in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment