public class MyException{
public void myFun() {
int[] array = new int[3];
try{
for(int i=0;i<4;++i){
array[i] = i;
}
System.out.println(array);
}catch(ArrayIndexOutOfBoundsException e){
//printed just to inform that we have entered the catch block
System.out.println(e.toString()+"\n");
//System.out.println("Oops, we went to far, better go back to 0!");
}
}
public static void main(String Args[]){
MyException me= new MyException();
try{
me.myFun();
me.myMethod();
}catch(Exception e){System.out.println(e.toString()+"\n");}
}
public void myMethod() throws ArithmeticException{
throw new ArithmeticException();
}
}
public void myFun() {
int[] array = new int[3];
try{
for(int i=0;i<4;++i){
array[i] = i;
}
System.out.println(array);
}catch(ArrayIndexOutOfBoundsException e){
//printed just to inform that we have entered the catch block
System.out.println(e.toString()+"\n");
//System.out.println("Oops, we went to far, better go back to 0!");
}
}
public static void main(String Args[]){
MyException me= new MyException();
try{
me.myFun();
me.myMethod();
}catch(Exception e){System.out.println(e.toString()+"\n");}
}
public void myMethod() throws ArithmeticException{
throw new ArithmeticException();
}
}
No comments:
Post a Comment