系统异常

*注意:系统异常的时候不需要抛出异常(系统已经抛出了和声明了,只是没写出来),在调用方法时用trycatch来处理异常即可
*/
public class Demo7 {
public static void main(String[] args) throws ArithmeticException
{
Math2 math2 = new Math2();
//一旦方法声明了异常,在调用方法的位置我们就要进行处理 1.继续声明 2.trycatch
math2.div(3, 0);

    //第二种方式

// try{
// math2.div(3, 0);
// }catch(ArithmeticException e){
// e.printStackTrace();
// }
}
}

class Math2{
public int div(int a,int b) throws ArithmeticException//通过throws实现异常的声明,告诉别人我有可能发生异常
{
return a/b;
}
}

你可能感兴趣的:(系统异常)