其他分享
首页 > 其他分享> > 异常的处理

异常的处理

作者:互联网

        异常的处理
处理异常的五个关键字:
try 尝试处理 catch 捕获 finally 无论执行不执行都会走
通过 throw和thorws用于抛出异常

public class Test01 {
public static void main(String[] args) {
try {
new Test01().add(1, 0);
} catch (ArithmeticException e) {
e.printStackTrace();
} finally {
}
}

public void add(int a, int b) throws ArithmeticException {
if (b == 0) {
throw new ArithmeticException();//主动抛出异常一般在方法中使用
}
}
}

标签:处理,ArithmeticException,throw,add,Test01,异常,public
来源: https://www.cnblogs.com/FeiFei2002/p/15658399.html