系统异常

*注意:系统异常的时候不需要抛出异常(系统已经抛出了和声明了,只是没写出来),在调用方法时用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;
}
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容