• 2021-04-14
    getCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果
    public void getCustomerInfo() {
    try {
    // do something that may cause an Exception
    } catch (java.io.FileNotFoundException ex){
    System.out.print("FileNotFoundException!");
    } catch (java.io.IOException ex){
    System.out.print("IOException!");
    } catch (java.lang.Exception ex){
    System.out.print("Exception!");
    }
    }
  • D)FileNotFoundException!IOException!Exception!

    内容

    • 0

      请说出下列程序的输出结果_____________,_____________。import java.io.IOException;public class E {public static void main(String args[]){try { methodA();}catch(IOException e){System.out.print("你好");return;}finally {System.out.println("thanks");}}public static void methodA() throws IOException{throw new IOException();}}

    • 1

      import java.io.IOException;  public class ExceptionTest(  public static void main (String[]args)  try (  methodA();  ) catch (IOException e)  (  system.out.printIn(“Caught IOException”);  ) catch (Exception e)   (  system.out.printIn(“Caught Exception”);  )  )  public void methodA ()   {  throw new IOException ();  }   What is the result?() A:  The code will not compile. B:  The output is caught exception. C:  The output is caught IOException. D:  The program executes normally without printing a message.

    • 2

      (9-3)请阅读程序,然后写出程序运行结果。(请注意输出不换行) public class Demo3 { public static void main(String[] args) { int a=9,b=0; double x=9,y=0; try { int c=a/b; }catch(Exception e1) { System.out.print("1"); try { double z=x/y; }catch(Exception e2) { System.out.print("2"); }finally { System.out.print("3"); } }finally { System.out.println("4"); } } }

    • 3

      下面程序的执行结果是( )。public class Test {public static void main(String[] args) {new Test().test();}public void test(){try{System.out.print("try");}catch(ArrayIndexOutOfBoundsException e){System.out.print("catch1");}catch(Exception e){System.out.print("catch2");}finally{System.out.println("finally");}}} A: try finally B: try catch1 finally C: try catch2 finally D: finally

    • 4

      当编译并且运行下面程序时会出现什么结果? public class ThrowsDemo{ static void throwMethod() { System.out.print("Inside throwMethod"); throw new IOException("demo"); } public static void main(String [] args){ try{ throwMethod(); }catch(IOException e){ System.out.println("Cauht"+e); } } }