举例1:异常的概念
public class Test
{
public int result(int x,int y){
int r = x/y;
return r;
}
}
public class TestException
{
public static void main(String[] args){
new Test().result(3,0);
System.out.println("Program is running here.");
}
}
举例2:异常的处理
public class Test
{
public int devide(int x,int y){
if(y != 0){
int result = x/y;
return result;
}
else{
return 8888;
}
}
}
public class TestException
{
public static void main(String[] args){
int t = new Test().devide(3,0);
System.out.println("结果:" + t);
}
}
原文:http://www.cnblogs.com/zhanghong/p/5266888.html