import java.io.*;
public class testExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
try{
process(1);
process(2);
process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
public class testExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
try{
process(1);
process(2);
process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
public class TestExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
TestExceptionProc tep=new TestExceptionProc();
try{
tep.process(1);
tep.process(2);
tep.process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
public class testExceptionProc
{
int x=5,y,result;
int a[]={1,2};
public static void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{ try{
process(1);
process(2);
process(3);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
import java.io.*;
public class testExceptionProc
{
static int x=5,y,result;
static int a[]={1,2};
public static void process(int i){
if(i==1) System.out.println("输入1时无异常");
if(i==2) result=x/y;
if(i==3) a[9]=26;
}
public static void main(String[] args)
{
for(int i=1;i<=3;i++){
try{
process(i);
}
catch(ArithmeticException e){
System.out.println("算术异常已做了处理");}
catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组下标越界异常已作处理");}
catch(Exception e){
System.out.println(e.toString());
return;}
}
}
}
改成static也可以执行,但是这就没有用到任何面向对象的思想了,给你的代码不参考……既然问题解决了,就结贴给分吧