Re: [問題]處理static constructor中的exception

看板java作者 (Believing is seeing! ^^)時間19年前 (2006/10/29 03:03), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《hyk.bbs@bbs.wretch.cc (夏天的微笑)》之銘言: : static constructor中的exception是不是只能在該static constructor中處理掉? : 有辦法將exception丟出去嗎? : class A{ : static{ : try{ : throw new Exception("a"); : }catch(Exception e){ : //handle the exception : } : } : } : 像上面這個程式,有可能將處理exception的區塊移到其他地方嗎?   硬要丟出去是有辦法的,   問題是你是想丟給誰處理呢?   在由 JVM 自動幫你 load class 的情況下,   你丟出去的 Exception 會是 JVM 接到的,   然後 JVM 會再丟出 ExceptionInInitializerError,   這是你要的嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.175.146.106
文章代碼(AID): #15Gwbzbw (java)
文章代碼(AID): #15Gwbzbw (java)