拿自定义异常没有办法,写的代码还有错
package untitled5;
import java.lang.*;
class NonEvenNumberException
extends Exception {
public NonEvenNumberException(String message) {
super("无偶数异常");
}
}
class SameIntReturnException
extends Exception {
public SameIntReturnException(String message) {
super("返回的结果相同异常");
}
}
public class CustomException {
public CustomException() {
}
public static void main(String[] args) {
CustomException customexception = new CustomException();
int i;
int result;
int[] divisor = {
4, 8, 15, 32, 64, 127, 256, 512};
int[] dividend = {
2, 1, 2, 4, 4, 4, 8};
for (i = 0; i < divisor.length; i++) {
try {
result = divisor[i] / dividend[i];
if ( (result % 2) != 0) {
throw new NonEvenNumberException();
}
if (dividend[i] == 1) {
throw new SameIntReturnException();
}
}
catch (ArrayIndexOutOfBoundsException exc) {
System.out.println("没有匹配的数据");
}
catch (NonEvenNumberException en) {
System.out.println(en);
}
catch (SameIntReturnException es) {
System.out.println(es);
}
}
}
}
在红字处总是提示"CustomException.java": cannot find symbol; symbol : constructor NonEvenNumberException(), location: class untitled5.NonEvenNumberException at line 36, column 17
"CustomException.java": cannot find symbol; symbol : constructor SameIntReturnException(), location: class untitled5.SameIntReturnException at line 39, column 17
这个我总是改不出来,哪位大大帮个忙啊!