2014-11-24 76 views
1

我有一個方法被定義爲:未報告的異常......必須被捕獲或聲明爲拋出;儘管*拋出*關鍵字

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 
; 

當我嘗試來包裝嘗試呼叫...捕獲錯誤逗留和它帶來了肛這個錯誤說明了Exception從來沒有被拋出。我該如何補救?我使用javase7和netneans 8

+0

可能是你在方法級拋出的異常包與預期的包不同。廣泛關注PolicyException類的包名稱! – hemanth 2014-11-24 08:00:45

+0

是的,我從錯誤的包中導入。現在修復它,謝謝。 – Lym 2014-11-24 08:11:54

回答

1

既然你沒有向我們展示實際的編譯錯誤等,我不能確定,但​​我懷疑有多個類叫做PolicyException,而且你聲明瞭錯誤的類:

  • 檢查編譯錯誤(S)

  • 檢查import語句的準確措辭。

+0

謝謝@Stephen C,我輸入了錯誤的「PolicyException」。永遠不可能從編譯器消息中弄清楚這一點。 – Lym 2014-11-24 08:08:05

相關問題