异常的抛出
div的异常抛给main来处理:
class Math{
public int div(int i,int j)throws Exception{
int temp=i/j;
return temp;
}
}
public class ThrowsDemo01 {
public static void main(String[] args){
Math m=new Math();
try {
System.out.println("Divation opration: "+m.div(10, 0));
} catch (Exception e) {
e.printStackTrace();
}
}
}