Re: [問題] Exception的問題
※ 引述《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)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
java 近期熱門文章
PTT數位生活區 即時熱門文章