zoukankan      html  css  js  c++  java
  • 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>);
    }
    

    }

  • 相关阅读:
    278.First Bad Version
    277. Find the Celebrity
    256.Paint House
    276. Paint Fence
    275. H-Index II
    274. H-Index
    273. Integer to English Words
    272. Closest Binary Search Tree Value II
    270. Closest Binary Search Tree Value
    271. Encode and Decode Strings
  • 原文地址:https://www.cnblogs.com/jpfss/p/9487806.html
Copyright © 2011-2022 走看看