V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
hazard
V2EX  ›  问与答

Java 学习小问题

  •  
  •   hazard · 2014-06-08 14:26:47 +08:00 · 2149 次点击
    这是一个创建于 3622 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    2014-06-08 22:08:10 +08:00
    hazard
        1
    hazard  
    OP
       2014-06-08 14:56:58 +08:00
    额。。。明白了。。。
    shoumu
        2
    shoumu  
       2014-06-08 14:57:47 +08:00   ❤️ 1
    也可以啊,放里面的话在捕捉到异常的时候才执行System.out.println("Time out");了

    另:推荐用gist贴代码
    terrens
        3
    terrens  
       2014-06-08 22:08:10 +08:00   ❤️ 1
    InterruptedException是给线程被中断例外用的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5730 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:57 · PVG 13:57 · LAX 22:57 · JFK 01:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.