【发布时间】:2014-11-24 15:56:15
【问题描述】:
我有一个方法被定义为:
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;必须被捕获或声明为抛出。我不知道为什么它建议我可以抛出,但“抛出”就在方法签名中。
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 的主体中抛出。我该如何补救?我正在使用 javase7 和 netneans 8
【问题讨论】:
-
可能是你在方法级别抛出的异常包与预期的包不同。广泛关注 PolicyException 类的包名!!
-
是的,我从错误的包中导入。现在修好了,谢谢。
标签: java netbeans exception-handling