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

}

原文地址:https://www.cnblogs.com/jpfss/p/9487806.html