我在一个方法里面 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
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
Exception类是Throwable 的子类,你想抛出e,但是你的这个e是XBRLException类型的。
不是继承了Exception类的话,是不可能用IOException 抛出的。
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)方法
构造方法是不会继承的
1.要莫在catch块中添加try,catch语句
2.要末在方法的声明处抛出Exception
1、IOException()
2、IOException(String s)
在这里throw new IOException("The data store could not be read.");
就可以了
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{
}
}
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{
}
}
IOException(String message, Throwable cause)
Constructs an IOException with the specified detail message and cause.
这是什莫