From: Martin D. <mar...@te...> - 2003-04-11 20:34:52
|
James Macgill a =E9crit: > Should it be up to the calling method to check that the value returned=20 > is not null or should we propagate the exception (either as an=20 > IllegalFeature or as a new exception) I vote for propagating the exception. Generally, I think that exceptions should never be eaten except if: * There is good reason to believe that this exception should never happen (then, I suggest to rethrow the exception as an AssertionError or something like that). * The method is capable to fallback on a default behavior which would still produces what the user expects (for example fallback on a longer computation path. Longer, but still work). * The exception occurs in some low-level library. Then, it should be wrapped (with Throwable.setCause(...)) in a higher level exception and rethrow. For example a DataSource may fails because of a SQLException or an IOException. This low-level exception should be wrapped into a DataSourceException and rethrow as DataSourceException. This is especially important for checked exception, which=20 IllegalFeatureException is. There is usually good reason why the=20 exception was checked in the first place, and eating it defeat the=20 purpose of checked exception. Martin. |