异常的处理

        异常的处理
处理异常的五个关键字:
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();//主动抛出异常一般在方法中使用
}
}
}
上一篇:kotlin更多语言结构——>异常


下一篇:Python re module (regular expressions)