Re: [問題] Exception的問題

看板java作者 (斯文狂野小幼狼≧﹏≦)時間19年前 (2006/04/17 11:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《oabgg (佑子)》之銘言: : 程式碼大致如下 : ===================================================================== : public class Translator extends Loader{ : public static void main(String args[]) throws Exception{ : new Translator().Translator(); : } : public void Translator() throws Exception{ ^^^^^^^^^^^^^^^^ 既然下面都已經catch了,為什麼還要throw呢 : try{ : ...... : unit(refPath); : ...... : moveFile(refPath,array[i]); : ...... : }catch(IOException e){ : throw new IOException(e.getMessage()); : }catch(SQLException e){ : throw new SQLException(e.getMessage()); : }catch(Exception e){ : throw new Exception(e.getMessage()); : }finally{ : ......... : } : } 接在method後面的throws Exception是說 在該method裡面的code可能產生exception,可是你沒有catch,所以才要丟出去 給其他上層的程式(呼叫這個method的) 來處理 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.184.17 ※ 編輯: Mylesksf 來自: 220.133.184.17 (04/17 12:05)
文章代碼(AID): #14Gn9M0H (java)
討論串 (同標題文章)
文章代碼(AID): #14Gn9M0H (java)