runtimeException也是能夠捕獲的


如題,
運行結果: 

bbb
abcdef

@Test
public void testRuntimeException() {
    int a = 0;
<span style="color:#000080;"><strong>try </strong></span>{
    aaa333();
} <span style="color:#000080;"><strong>catch </strong></span>(Exception ex) {
    System.<span style="color:#660e7a;"><strong><em>out</em></strong></span>.println(<span style="color:#008000;"><strong>"bbb"</strong></span>);
}

System.<span style="color:#660e7a;"><strong><em>out</em></strong></span>.print(<span style="color:#008000;"><strong>"abcdef"</strong></span>);

}

private void aaa333() {
int a = 0;

<span style="color:#000080;"><strong>try </strong></span>{
    <span style="color:#000080;"><strong>int </strong></span>b = <span style="color:#0000ff;">32 </span>/ a;
} <span style="color:#000080;"><strong>catch </strong></span>(Exception ex) {
    <span style="color:#000080;"><strong>throw new </strong></span>RuntimeException(<span style="color:#008000;"><strong>"error;"</strong></span>);
}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM