诱人的老师中文字幕在线观看
遊客:  註冊 | 登錄 | 幫助





標題: [討論] 簡單 Java 問題
mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-2-8 01:12 AM  資料  個人空間  短訊  加為好友 
簡單 Java 問題

X-Seek
此 X-Seek 主題價值 50 XS。 (天藍出手)
X-Seek 出題者 mickeyGoUp 希望能在 2007-2-22 01:12 AM 前尋找到解決方案。
已於 2007-2-12 01:30 AM 由 mickeyGoUp 選出最合適的解決方案及關閉 X-Seek 主題。

我有個問題﹐但冇時間去寫 codes 求證﹐想睇下有冇人知答案?  

public method1() throws SQLException {
    try {
        method2();

    } catch (SQLException se) {
        System.err.println("HERE A");

    } catch (NullPointerException ne) {
        System.err.println("HERE B");
    }
}

public method2() throws SQLException {
    try {
        someObj.call();

    } catch (SQLException se) {
        System.err.println("HERE C");

    } catch (IllegalArgumentException ie) {
        System.err.println("HERE D");
    }
}

如果 someObj.call() throw 左 NullPointerException﹐咁響 standard error 會見到邊句呢 (HERE A, HERE B, HERE C, or HERE D)?  定係會有其他呢?



[ 觀看解決方案 ]


最後編輯: mickeyGoUp : 2007-2-8 04:44 AM
頂部

lhy     Rank: 3
青出藍
性別 男
UID 14043

精華 0
帖子 121
積分 330   詳情

閱讀權限 40
註冊 2006-10-16
來自 Netherlands
狀態 離線

 
 
 
 
發表於 2007-2-9 11:00 PM  資料  個人空間  短訊  加為好友 
I have the answer.... You will get error while compiling why? you have make 2 constructors instead of methodes whhahahahahah

public void method1() throws SQLException {
    try {
        method2();

    } catch (SQLException se) {
        System.err.println("HERE A");

    } catch (NullPointerException ne) {
        System.err.println("HERE B");
    }
}

public void method2() throws SQLException {
    try {
        someObj.call();

    } catch (SQLException se) {
        System.err.println("HERE C");

    } catch (IllegalArgumentException ie) {
        System.err.println("HERE D");
    }
}

when a exception occurs then the program will break his current operation. So That means when someObj throws a NullPointerException that will return to methode1. Methode1 will catch it with "HERE B".




X-Seek 解決方案 1/1   


最後編輯: lhy : 2007-2-9 11:14 PM
頂部



mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-2-9 11:33 PM  資料  個人空間  短訊  加為好友 


QUOTE:
原帖由 lhy 於 2007-2-9 10:00 AM 發表
I have the answer.... You will get error while compiling why? you have make 2 constructors instead of methodes whhahahahahah

Hehehe.. constructor name should match with the class name.  I did not say what the class name was, why did you say I have made two constructors?  

QUOTE:
原帖由 lhy 於 2007-2-9 10:00 AM 發表
when a exception occurs then the program will break his current operation. So That means when someObj throws a NullPointerException that will return to methode1. Methode1 will catch it with "HERE B".

Thank you.  That's what I thought.  The exception should "bubble up".

頂部

lhy     Rank: 3
青出藍
性別 男
UID 14043

精華 0
帖子 121
積分 330   詳情

閱讀權限 40
註冊 2006-10-16
來自 Netherlands
狀態 離線

 
 
 
 
發表於 2007-2-11 08:23 AM  資料  個人空間  短訊  加為好友 
Nope you should always define the return type. But you didnt that means you are making a constructor. check my code "void"


"bubble up"????? WTF is that



最後編輯: lhy : 2007-2-11 08:24 AM
頂部

mickeyGoUp     Rank: 7Rank: 7Rank: 7
版主
性別 男
UID 5

精華 0
帖子 35511
積分 5235   詳情

閱讀權限 150
註冊 2006-3-24
來自 美國滴滴尼
狀態 離線

 
 
 
 
發表於 2007-2-12 01:28 AM  資料  個人空間  短訊  加為好友 


QUOTE:
原帖由 lhy 於 2007-2-10 07:23 PM 發表
Nope you should always define the return type. But you didnt that means you are making a constructor.  check my code "void"

You are right.    That was a mistake.  I thought I had typed void.  

QUOTE:
原帖由 lhy 於 2007-2-10 07:23 PM 發表
"bubble up"????? WTF is that

"bubble up" is the term we use to describe when a runtime exception is thrown in a method but did not get caught, it will "go up" one level to the caller, if it stills doesn't get caught, it will go up another level...etc..  

頂部

lhy     Rank: 3
青出藍
性別 男
UID 14043

精華 0
帖子 121
積分 330   詳情

閱讀權限 40
註冊 2006-10-16
來自 Netherlands
狀態 離線

 
 
 
 
發表於 2007-2-12 07:17 AM  資料  個人空間  短訊  加為好友 
I always caught the superclass Exception. So will get all errors no matter what. Except I need to return specify feedback to the user.

頂部

  larrylee_00     Rank: 2Rank: 2
藍之初
性別 保密
UID 29127

精華 0
帖子 15
積分 100   詳情

閱讀權限 30
註冊 2007-4-17
來自
狀態 離線

 
 
 
 
發表於 2007-4-17 09:44 AM  資料  個人空間  短訊  加為好友 
Oh boy, I think there is a lot of smart people out there who can answer all different questions.

頂部

快速美言
           


當前時區 GMT+8, 現在時間是 2024-4-20 02:21 PM

    Powered by Discuz!  © 2001-2007 Comsenz Inc.   
Processed in 0.019030 second(s), 9 queries

清除 Cookies - 聯繫我們 - LIPS Corner 新天藍 - Archiver