在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ Java:Throwable編譯錯誤must be caught or decl

Java:Throwable編譯錯誤must be caught or declared to be thrown

下面的語句中,如果throw t1 換成 throw t 就會有編譯錯誤,說是must be caught or declared to be thrown,為啥?

    try{
        FileInputStream fis = new FileInputStream(file);
        Throwable t = null;
        try{
            fis.read();
        }catch (Throwable t1){
            t = t1;
            throw t1;
        } finally{
            ...
        }
    } catch(Exception e){
        ...
    }
回答
編輯回答
絯孑氣

除了RuntimeException及其子類,其他異常都是要處理的
我奇怪的是難道你throw t1就能編譯通過了?

編輯:
最外層catch的是Exception,t是Throwable,是Exception的父類對象,捕獲不到,可以把最外層Exception改成Throwable看看
而t1實際上是IOException所以可以捕獲

2017年4月26日 05:22