V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
hazard
V2EX  ›  问与答

Java 学习小问题

  •  
  •   hazard · Jun 8, 2014 · 2719 views
    This topic created in 4344 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   ·   2726 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 175ms · UTC 13:03 · PVG 21:03 · LAX 06:03 · JFK 09:03
    ♥ Do have faith in what you're doing.