package java151227;
//RuntimeException
/*
* Exception中RuntimeException比较特殊!
* 如果在函数内抛出该异常:函数上可以不用声明,编译通过
* 调用者可以不用处理,编译一样通过!
*/
public class ExceptionDemo {
public static void main(String[] args) {
Demo demo =new Demo();
int x= demo.div(4, 0);
System.out.println("x="+x);
System.out.println("over!");
}
}
//ArithmeticException
class Demo{
/**
* 两个整型数相除
* @param a 被除数
* @param b 除数
* @return 返回商
*/
int div(int a ,int b) throws ArithmeticException
{
// if (b==0) {
// throw new ArithmeticException("除数为0!");
// }
return a/b;
}
}
//RuntimeException
/*
* Exception中RuntimeException比较特殊!
* 如果在函数内抛出该异常:函数上可以不用声明,编译通过
* 调用者可以不用处理,编译一样通过!
*/
public class ExceptionDemo {
public static void main(String[] args) {
Demo demo =new Demo();
int x= demo.div(4, 0);
System.out.println("x="+x);
System.out.println("over!");
}
}
//ArithmeticException
class Demo{
/**
* 两个整型数相除
* @param a 被除数
* @param b 除数
* @return 返回商
*/
int div(int a ,int b) throws ArithmeticException
{
// if (b==0) {
// throw new ArithmeticException("除数为0!");
// }
return a/b;
}
}