用户自定义异常的一点疑问
用户自定义异常需要 继承 内置异常类
但是下面关于用户自定义异常的例子 却没继承内置异常类
到底该如何理解自定义异常类
class UserExceptionDemo {
int size, array[];
UserExceptionDemo(int s) {
size = s;
try { checkSize(); }
catch(ArraySizeException e) {System.out.println(e);}
}
void checkSize() throws ArraySizeException {
if(size < 0) throw new ArraySizeException();
array = new int[size];
for(int i = 0; i < size; i++) {
array[i] = i+1;
System.out.print(array[i]+" ");
}
}
public static void main(String arg[]) {
new UserExceptionDemo(Integer.parseInt(arg[0])); }
}