私のサンプルコードは次のとおりです:
public class ExceptionsDemo {
public static void main(String[] args) {
try {
int arr[]={1,2,3,4,5,6,7,8,9,10};
for(int i=arr.length;i<10;i++){
if(i%2==0){
System.out.println("i =" + i);
throw new Exception();
}
}
} catch (Exception e) {
System.err.println("An exception was thrown");
}
}
}
私の要件は、例外がキャッチされた後、配列の残りの要素を処理することです。これどうやってするの?
コードは次のようになります。
public class ExceptionsDemo {
public static void main(String[] args) {
for (int i=args.length;i<10;i++){
try {
if(i%2==0){
System.out.println("i =" + i);
throw new Exception(); // stuff that might throw
}
} catch (Exception e) {
System.err.println("An exception was thrown");
}
}
}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加