Apache Error与throws类不兼容

时间:2011-08-10 17:56:13

标签: apache grails error-handling

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

方法如下:

import org.apache.http.client.HttpResponseException

class RestSearchService implements SearchService {
    List<Person> getPersonSearch( String fName, String lName) throws HttpResponseException {
        ...
        //  Make the call
        ...
    }
}

然后我在控制器中捕获抛出的异常以重定向到错误页面。我已经测试了它,这段代码似乎运行正常。问题是上面的方法有下划线(我正在使用SpringSource Tool Suite用于IDE)并且说

Exception HttpResponseException is not compatible with 
throws clause in SearchService.getPersonSearch(String, String)

有谁知道可能导致这种情况的原因?此外,这是否意味着存在实际问题或情况会导致应用程序崩溃?就像我说的那样,从我可以看出,抛出/重定向就像一个冠军一样,但是这个错误使我对将应用程序转移到生产中感到紧张。

提前致谢,

-Mike

1 个答案:

答案 0 :(得分:1)

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

它是这样的:

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

或者像这样:

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

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