这是一个创建于 3659 天前的主题,其中的信息可能已经有所发展或是发生改变。
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](https://cdn.v2ex.com/avatar/878d/5255/44561_normal.png?m=1388458068) |
|
1
hazard 2014-06-08 14:56:58 +08:00
额。。。明白了。。。
|
![shoumu](https://cdn.v2ex.com/avatar/56c1/2a45/26787_normal.png?m=1394535488) |
|
2
shoumu 2014-06-08 14:57:47 +08:00 1
也可以啊,放里面的话在捕捉到异常的时候才执行System.out.println("Time out");了
另:推荐用gist贴代码
|
![terrens](https://cdn.v2ex.com/gravatar/efedc605104446e1eb1d92e4a43c205d?s=48&d=retro) |
|
3
terrens 2014-06-08 22:08:10 +08:00 1
InterruptedException是给线程被中断例外用的。
|