Women in Technology

Hear us Roar



Article:
  Best Practices for Exception Handling
Subject:   Just crap, read http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html instead
Date:   2008-07-31 00:10:57
From:   kdgar
Response to: Just crap, read http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html instead

I agree with this comment. The article is misleading and incomplete. It also contradicts itself. "Username already exists" is not a programming error, which is what you state RuntimeExceptions are for.


The analysis of SQLException is also incorrect. What are the options of the data tier? To return a null value after the exception is caught? Wrong. The null value is completely ambiguous. While my business tier should not necessarily know that I am using a SQL data source, it should absolutely know that something is wrong. If you're worried about encapsulation, wrap the SQLException with something more abstract, like a DataSourceException.


Exceptions are not about convenience for the caller. It's about letting the the caller know that you are not able to fully uphold the contract of executing the request that was made.


This article should be revoked to avoid spreading bad habits.