繁体   English   中英

未报告的异常…必须被捕获或声明为抛出; 尽管* throw *关键字

[英]Unreported exception … must be caught or declared to be thrown; despite *thrown* keyword

我有一个方法被定义为:

private void startUSSDNotification(SimpleReference reference,
                                   String ussdServiceActivationNumber,
                                   String criteria)
    throws PolicyException {
    // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe.
    // If the calling of port operations may lead to race condition some synchronization is required.
    USSDNotificationManager port = service.getUSSDNotificationManager();
    port.startUSSDNotification(reference, ussdServiceActivationNumber,
                               criteria);
}

编译器发牢骚,“未报告的异常PolicyException;必须被捕获或声明为抛出。我不知道为什么它建议我可以抛出但方法签名中仍然存在” throw”。

startUSSDNotification定义为:

public void startUSSDNotification(
    @WebParam(name = "reference", targetNamespace = "http://www.csapi.org/schema/osg/ussd/notification_manager/v1_0/local")
    SimpleReference reference,
    @WebParam(name = "ussdServiceActivationNumber", targetNamespace = "http://www.csapi.org/schema/osg/ussd/notification_manager/v1_0/local")
    String ussdServiceActivationNumber,
    @WebParam(name = "criteria", targetNamespace = "http://www.csapi.org/schema/osg/ussd/notification_manager/v1_0/local")
    String criteria)
    throws PolicyException, ServiceException
;

当我尝试将调用包装在try ... catch中时,错误仍然存​​在,并且会弹出另一个错误,指出try的主体从未抛出Exception异常。 我该如何补救? 我正在使用javase7和netneans 8

由于您没有向我们展示实际的编译错误等,因此不能确定,但​​是我怀疑有多个类称为PolicyException ,并且您在声明错误的类:

  • 检查编译错误的准确措辞

  • 检查您的import声明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM