class A
{
public void method throws IOException(){}
}
// 错误
class B
{
public void method throws FileNotFoundException(){}
}
// 错误
class C
{
public void method throws Exception(){}
}
// 错误
class D
{
public void method throws IOException,MyException(){}
}
// 正确
class F
{
public void method(){}
}
重写的方法必须和原方法抛出的异常一致或者不抛异常
异常处理与方法重写
本文探讨了Java中方法重写时异常处理的一致性原则,包括如何正确地抛出和处理异常,确保代码的健壮性和兼容性。

被折叠的 条评论
为什么被折叠?



