为什么我的代码似乎绕过了这个异常?

and*_*and 0 java multithreading exception

鉴于此代码:

public class TwoThreads {
    static Thread laurel, hardy;

    public static void main(String[] args) {
         laurel = new Thread() {
             public void run() {
                 System.out.println("A");
                 try {
                     hardy.sleep(1000);
                 } catch (Exception e) {
                     System.out.println("B");
                 }
                 System.out.println("C");
             }
         };

         hardy = new Thread() {
             public void run() {
                 System.out.println("D");
                 try {
                     laurel.wait();
                 } catch (Exception e) {
                     System.out.println("E");
                 } 
                 System.out.println("F");
             }
         };
         laurel.start();
         hardy.start();
     }
}
Run Code Online (Sandbox Code Playgroud)

输出包括:

A C D E and F
Run Code Online (Sandbox Code Playgroud)

我很困惑为什么包含F,因为IllegalMonitorStateExceptionsynchronized代码之外调用wait()时会抛出一个.为什么达到F的印刷声明?我相信线程堆栈随后会爆炸,但程序应该将控制传递给它的主堆栈.

它是否正确?

Fra*_* IV 6

您正在捕获打印"E"的块中的异常,从而有效地吞咽它.然后代码将继续打印"F".由于这个原因,仅仅捕获异常而不执行任何其他操作的块是危险的.