集册 Java实例教程 要捕获与继承无关的多个不同异常,请对单个尝试使用多个catch块

要捕获与继承无关的多个不同异常,请对单个尝试使用多个catch块

欢马劈雪     最近更新时间:2020-01-02 10:19:05

570
要捕获与继承无关的多个不同异常,请对单个尝试使用多个catch块
/*nowjava.com - 时代Java 提 供*/

try { 

        // code that might generate exceptions 

    } catch  (IOException ioe) { 

        System .out.println ("Input/output error"); 

        System .out.println (ioe.getMessage ()); 

    } catch  (ClassNotFoundException cnfe) { 

        System .out.println ("Class not found"); 

        System .out.println (cnfe.getMessage ()); 

    } catch  (InterruptedException ie) { 

        System .out.println ("Program interrupted"); 

        System .out.println (ie.getMessage ()); 

    }