Apache Error与抛出类不兼容



我有一个快速的问题。在我的grails项目中,我正在进行一些web服务调用。如果没有足够的字符供搜索,其中一个调用(对于搜索函数)就会超时。我不能增加所需字符的数量,所以我试图捕获异常,并显示一个错误页面,要求用户添加更详细的参数。

方法如下:

import org.apache.http.client.HttpResponseException
class RestSearchService implements SearchService {
    List<Person> getPersonSearch( String fName, String lName) throws HttpResponseException {
        ...
        //  Make the call
        ...
    }
}
然后在控制器中捕获抛出的异常,以重定向到错误页面。我已经测试了它,这段代码似乎工作得很好。问题是上面的方法被加了下划线(我在IDE中使用SpringSource Tool Suite),并且说
Exception HttpResponseException is not compatible with 
throws clause in SearchService.getPersonSearch(String, String)

有谁知道这可能是什么原因吗?此外,这是否意味着存在导致应用崩溃的实际问题或情况?就像我说的,据我所知,throw/redirect工作得很好,但这个错误让我对将应用程序投入生产感到紧张。

提前感谢,

迈克

我会说你的接口SearchService是不对的!接口中的方法'getPersonSearch'的签名是什么?

是这样的:

List<Person> getPersonSearch( String fName, String lName);

或者像这样:

List<Person> getPersonSearch( String fName, String lName) throws HttpResponseException;

第二个是正确的,如果你有第一个,那应该是问题!

最新更新