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