InterruptedException的疑问
public class TestSleep {
public TestSleep() {
}
public static void main(String[] args) {
SleepingThread sleep=new SleepingThread();
System.out.println("interrupt sleep thread");
sleep.interrupt();
}
}
class SleepingThread extends Thread{
public SleepingThread(){
this.start();
}
public void run(){
System.out.println("entering sleep");
try {
this.sleep(100000);
}
catch (InterruptedException ex) {
ex.printStackTrace();
}
System.out.println("recovering from sleep");
}
}
如下是打印信息:
java.lang.InterruptedException: sleep interrupted
at java.lang.Thread.sleep(Native Method)
at com.zyb.thread.SleepingThread.run(TestSleep.java:32)
interrupt sleep thread
entering sleep
recovering from sleep
现在的问题是:为什么首先打印的是有关异常的信息了?