编译程序时出现此错误:
./GUI/mainWindow.java:30: error: unreported exception Exception; must be caught or declared to be thrown
clientUI.initClientUI();
^
1 error
但我的方法实际上抛出了异常:
public final void initClientUI() throws Exception {
但是,如果我删除“抛出异常”部分,尝试编译,然后再次添加,程序编译成功。谁能解释为什么会这样?
编辑:
如果我将“抛出异常”添加到我正在调用的方法中
public void actionPerformed(ActionEvent e) throws Exception { //<-----add Exception there
ClientWindow clientUI = new ClientWindow();
clientUI.initClientUI();
我收到此错误:
./GUI/mainWindow.java:28: error: actionPerformed(ActionEvent) in <anonymous GUI.mainWindow$1> cannot implement actionPerformed(ActionEvent) in ActionListener
public void actionPerformed(ActionEvent e) throws Exception {
^
overridden method does not throw Exception
1 error