构造默认构造函数时不能处理异常:type由隐式超构造函数抛出的异常 [英] While constructing the default constructor can not handle exception : type Exception thrown by implicit super constructor
问题描述
代码工作正常,直到我尝试将代码编译成可构造的类。当我尝试从它构造一个对象时,我得到错误
The code works fine until I try to make the code into a constructable class. When I attempt to construct an object from it I get the error
默认构造函数不能处理由隐式超构造函数抛出的异常类型IOException。定义一个显式构造函数
"Default constructor cannot handle exception type IOException thrown by implicit super constructor. Must define an explicit constructor"
这是当必须抛出异常到 FileReader
和 BufferedReader
。
This is when having to throw exceptions to FileReader
and BufferedReader
.
谢谢
编辑: / p>
FileReader textFilethree = new FileReader (xFile);
BufferedReader bufferedTextthree = new BufferedReader (textFilethree) ;
String lineThree = bufferedTextthree.readLine();
xFile从构建中获取。注意,在这个构造中,异常被抛出。
The xFile is gotten from the construction. Note that within this construction exceptions are thrown.
推荐答案
默认构造函数隐式调用超级构造函数,它被假定为抛出一些异常,需要在子类的构造函数中处理。对于详细的答案发布代码
Default constructor implicitly invokes super constructor which is assumed to be throwing some exception which you need to handle in sub class's constructor . for detailed answer post the code
class Base{
public Base() throw SomeException{
//some code
}
}
class Child extends Base{
public Child(){
//here it implicitly invokes `Base()`, So handle it here
}
}
这篇关于构造默认构造函数时不能处理异常:type由隐式超构造函数抛出的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!