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>);
}

}

posted @ 2018-08-16 15:55  星朝  阅读(3099)  评论(0编辑  收藏  举报