Example
package com.vinod;
import java.util.*;
public class ExceptionTest {
public static void main(String[] args) {
List al = new ArrayList();
al.add("1");
al.add("5");
al.add("pretech");
al.add("6");
// iterating arraylist and expecting NumberFormat exception
for (int i = 0; i <= al.size() - 1; i++) {
try {
int a = Integer.parseInt((String) al.get(i));
System.out.println("value :" + a);
} catch (Exception e) {
try {
throw e;
} catch (Exception e1) {
System.out.println(e);
}
}
}
}
}
import java.util.*;
public class ExceptionTest {
public static void main(String[] args) {
List al = new ArrayList();
al.add("1");
al.add("5");
al.add("pretech");
al.add("6");
// iterating arraylist and expecting NumberFormat exception
for (int i = 0; i <= al.size() - 1; i++) {
try {
int a = Integer.parseInt((String) al.get(i));
System.out.println("value :" + a);
} catch (Exception e) {
try {
throw e;
} catch (Exception e1) {
System.out.println(e);
}
}
}
}
}
No comments:
Post a Comment