package com.day16.Exception;
/*
* 异常处理的两种方式
* 1.try...catch...finally
* *try catch
* *try catch finally
* *try finally
* 2.throws
* try:用来检测异常的
* catch:用来捕获异常的
* finally:释放资源
*/
public class ExceptionOne {
public static void main(String[] args) {
Demo d=new Demo();
try {
int x=d.div(10,0);
System.out.println(x);
}catch(ArithmeticException a) {//相当于ArithmeticException a=new ArithmeticException();
System.out.println("除数为0了");//除数为0了
}
System.out.println("Kobe");//Kobe
}
}
class Demo{
public int div(int a,int b) {
return a/b;
}
}