改成这样试试
public static void methodA () throws IOException{

解决方案 »

  1.   

    public static void methodA () {  throw new IOException ();
    }
    该成
    public static void methodA () {  
     try
     {
       throw new IOException ();
     }
     catch(Exception e){}
    }
      

  2.   

    无论怎么改后,结果还都是:ExceptionTest.java:5: Exception java.io.IOException is never thrown in the body
    of the corresponding try statement.
     catch (IOException e) { System.out.println("Caught IOException"); }
     ^
    实在不明白怎么回事?
      

  3.   

    try { methodA();}
     catch (IOException e) { System.out.println("Caught IOException"); }
    该成
    try { methodA();
       throw new IOException();
      }
     catch (IOException e) { System.out.println("Caught IOException"); }
      

  4.   

    import java.io.IOException;
     public class ExceptionTest{
     public static void main (String[]args) {
    try { 
    ExceptionTest tt = new ExceptionTest();
    tt.methodA();
    }
     catch (IOException e) { System.out.println("Caught IOException"); }
     catch (Exception e)  { System.out.println("Caught Exception"); }
    }
     public  void methodA() throws IOException{   throw new IOException();
    }
    }
      

  5.   

    谢谢 study_body(珍惜每一天) :
    这样好了,可不明白为什么 throw 一定要在调用方法后!在方法中 throw,调用后catch不就行了吗?
    跟调用顺序有什么关系吗?
      

  6.   

    你可以直接将public static void methodA () 
    变成public static void methodA () throws IOException
    也就是说,你必须有可能产生IO异常
      

  7.   

    那就是说跟throw在方法中还是在方法后的顺序没有关系了?