import java.util.*;
class ArrayOverflowException extends Exception{
ArrayOverflowException(){
super();
}
static int i;
static void check(int i) throws ArrayOverflowException{
if (i>5) {
throw new ArrayOverflowException("Array Overflow");
return;
}
}
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int a[]=new int[5];
System.out.println("Enter the elemets of the array. #MAX 6 ELEMENTS#");
try{
for (int i=0;i<10;i++) {
ArrayOverflowException.check(i);
a[i]=input.nextInt();
}
}catch (ArrayOverflowException e) {
System.out.println("Exception handled"+e);
}
}
}
私は、エラーcannot find symbol in line 9
を与えるJavaで独自のユーザー定義例外を作成しようとしています。助けてください。Javaでユーザ定義のエラーを作成する。なぜこのコードは機能しませんか?
行9は、新しいArrayOverflowException( "配列オーバーフロー")をスローします。
ための 'に変更し、それは、(i = 0をint型;私は<10; iが++){' –
は、私はすでにそれをやって試してみましたが、それはラインが9で違い – Palak
をしませんでしたか? – shmosel