[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lucene-dev
Subject:    Re: svn commit: r164695 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/search/Hit.j
From:       DM Smith <dmsmith555 () gmail ! com>
Date:       2005-04-26 20:43:13
Message-ID: 426EA7E1.2090503 () gmail ! com
[Download RAW message or body]

Erik Hatcher wrote:

> On Apr 26, 2005, at 2:38 PM, Daniel Naber wrote:
>
>> On Tuesday 26 April 2005 02:21, ehatcher@apache.org wrote:
>>
>>> +  public String toString() {
>>> +    try {
>>> +      return getDocument().toString();
>>> +    } catch (IOException e) {
>>> +      return null;
>>> +    }
>>> +  }
>>
>>
>> Wouldn't it be better here to re-throw the exception as a 
>> RuntimeException?
>
>
> I don't know.... would it?  I have no preference, though it seems ok 
> to me to simply return null since this is the toString method.  For a 
> Document, the toString is only useful for debugging anyway.

Two thoughts:
If getDocument().toString() cannot possibly throw an IOException, but it 
is part of the signature, then it does not matter.

Once lucene is at 1.4, it would be better to use an assert in the catch 
and not throw an error but return "" instead of null. The asserts can be 
removed at runtime by passing flags to the program. Assertions are best 
used for situations that should never happen.

public String toString()
{
    try {
       return getDocument().toString();
    } catch (IOException e) {
       assert false : e;
       return "";
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic