On 22.3.12 10:54, Julian Reschke wrote:
On 2012-03-22 11:04, Michael Dürig wrote:
Hi,
Here's my take at this: I'd use exceptions as sparingly as possible and
only for cases where something unexpected (an exception!) happens. That
is, I wouldn't use exceptions e.g. for items not being found. This is
clearly something that happens all the time and is by no means
unexpected.
For the cases where exceptions are involved I would define our own very
small set of exceptions and make them all *unchecked*. Checked
exceptions compose very badly wrt. lazyness. For example an iterator
which lazily fetches its items on next() has no clean way of handling
exceptions in the next() method.
Only at the very last instance (i.e. in the jcr component) I would
actually create and throw the various RepositoryExceptions.
Michael
I'm not a fan of the "unchecked" pattern, but I agree with not throwing
at all for expected things, such as NotFound. Which reminds me of
considering nullability annotations so that the contract is well-defined.
+1 for nullability annotations. We need to decide on which one to use
however. There seems to be quite a bit of a discussion [1].
If we use checked exceptions we should decide up front on how to work
around the composability issue. Otherwise we end up with zillions of
ad-hoc solutions.
*If* we use unchecked exceptions, by all means let them all extend a
common base exception :-)
Yes absolutely: +1
[1]
http://stackoverflow.com/questions/4963300/which-notnull-java-annotation-should-i-use
Best regards, Julian