Re: [問題]處理static constructor中的exception
※ 引述《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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):