我在一个方法里面 catch (XBRLException e) {
throw new IOException("The data store could not be read.", e);
}看了源代码 IOException 他public class IOException extends Exception exception里面有   public Exception(String message, Throwable cause) {
        super(message, cause);
    }
怎么用throw new IOException("The data store could not be read.", e) 说 the constructor IOException(String,XBRLException )  is undefined.XBRLException   public class XBRLException extends Exception 

解决方案 »

  1.   

    XBRLException类是不是你自己写的啊?有没有继承Exception类啊?
    Exception类是Throwable 的子类,你想抛出e,但是你的这个e是XBRLException类型的。
    不是继承了Exception类的话,是不可能用IOException 抛出的。
      

  2.   

    public
    class IOException extends Exception {
        /**
         * Constructs an <code>IOException</code> with <code>null</code>
         * as its error detail message.
         */
        public IOException() {
    super();
        }    /**
         * Constructs an <code>IOException</code> with the specified detail
         * message. The error message string <code>s</code> can later be
         * retrieved by the <code>{@link java.lang.Throwable#getMessage}</code>
         * method of class <code>java.lang.Throwable</code>.
         *
         * @param   s   the detail message.
         */
        public IOException(String s) {
    super(s);
        }
    }没有new IOException("The data store could not be read.", e)方法
    构造方法是不会继承的
      

  3.   

    因为你是在catch块中手动的抛出一个Exception,所以
    1.要莫在catch块中添加try,catch语句
    2.要末在方法的声明处抛出Exception
      

  4.   

    XBRLException  public class XBRLException extends Exception  已经 extends Exception 
      

  5.   

    IOException的构造方法:
    1、IOException()
    2、IOException(String s)
    在这里throw new IOException("The data store could not be read.");
    就可以了 
      

  6.   

    例子1,声明抛出exceptionimport java.io.IOException;
    public class Test6 { /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    try{
    Test9 test = new Test9();
    test.doWork();

    }catch(Testexception t){
    throw new IOException("file not found.", t);
    }

    }}class Testexception extends Exception{

    }class Test9{
    void doWork() throws Testexception{
    }
    }
      

  7.   

    例2,使用try,catchimport java.io.IOException;
    public class Test6 { /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    try{
    Test9 test = new Test9();
    test.doWork();

    }catch(Testexception t){
    try {
    throw new IOException("file not found.", t);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }

    }}class Testexception extends Exception{

    }class Test9{
    void doWork() throws Testexception{
    }
    }
      

  8.   

    确实IOException里没有IOException(String,Throwable )这个
      

  9.   


    IOException(String message, Throwable cause) 
              Constructs an IOException with the specified detail message and cause.
    这是什莫