directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Seelmann <>
Subject Re: [Shared] Cursor interface Excpetions
Date Sat, 05 Jun 2010 20:31:48 GMT
Emmanuel Lecharny schrieb:
> On 6/5/10 12:18 PM, Felix Knecht wrote:
>> Hash: SHA1
>> On 06/05/10 12:02, Emmanuel Lecharny wrote:
>>> On 6/5/10 11:57 AM, Felix Knecht wrote:
>>>> Hash: SHA1
>>>> The Cursor interface [1] throws almost for each method an
>>>> 'Exception'. I
>>>> suggest to make this less generic and throw either the (from javadoc)
>>>> "UnsupportedOperationException" or in analogy to the Iterator a
>>>> "NoSuchElementException" for methods like before,after,last,first, ...
>>> I saw that while I was propagating the LdapException through the server.
>>> IMO, we should define a base CursorException class, and derive some more
>>> specific exception like the one you suggest.
>> What would be the benefit of the Exception inflation instead of using
>> already existing ones where it logically makes sense?
> The idea is to use the best Exception for each error case. If the
> existing exceptions fit, then I think we can avoid defining our own tree
> of exceptions. But I doubt we can cover all the cases with those
> existing exception.
> As I'm not a specialist of the Store code, maybe Alex or Stefan can
> bring a bit more light on this aspect.

The package already defines
three exceptions, all extend "Exception":
- InvalidCursorPositionException
- InconsistentCursorStateException
- CursorClosedException

The InvalidCursorPositionException is thrown when calling Cursor.get()
but the cursor isn't positioned correctly. An option is to use a
NoSuchElementException instead.

The InconsistentCursorStateException is never used.

The CursorClosedException is thrown when Cursor.close() was called and
afterwards another cursor method is called. An option is to use an
IllegalStateException instead.

Other exceptions are thrown by the underlying data stores if there are
problems when getting data from an index table for example. I think most
of them are IOExceptions. Here it makes sense to define a custom
exception to wrap those guys.

The question is (and I think I can remember we already had such a
discussion): should we use checked or unchecked exceptions?

If we use checked exceptions it makes sense to define a base
CursorException and to derive the above mention exceptions from it.

If we use unchecked exceptions we should reuse the existing
IllegalStateException and NoSuchElementException.


Kind Regards,

View raw message