hazard
V2EX  ›  问与答

Java 学习小问题

  •  
  •   hazard · Jun 8, 2014 · 2782 views
    This topic created in 4375 days ago, the information mentioned may be changed or developed.
    public class sleep {
    public static void main(String[] args) {
    try {
    Thread.sleep(200);
    } catch (InterruptedException e) {}
    System.out.println("Time out");

    }
    }

    这个
    System.out.println("Time out");
    为何不能放到上面catch的大括号里面?
    3 replies    2014-06-08 22:08:10 +08:00
    hazard
        1
    hazard  
    OP
       Jun 8, 2014
    额。。。明白了。。。
    shoumu
        2
    shoumu  
       Jun 8, 2014   ❤️ 1
    也可以啊,放里面的话在捕捉到异常的时候才执行System.out.println("Time out");了

    另:推荐用gist贴代码
    terrens
        3
    terrens  
       Jun 8, 2014   ❤️ 1
    InterruptedException是给线程被中断例外用的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3784 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 96821589 · 39ms · UTC 04:32 · PVG 12:32 · LAX 21:32 · JFK 00:32
    ♥ Do have faith in what you're doing.