Day16-02
P77 异常01:Error和Exception






P78 异常02:捕获和抛出异常

package com.exception;
public class Test {
public static void main(String[] args) {
int a = 1;
int b = 0;
try {
System.out.println((a/b));
}catch (Error e){
System.out.println("Error");
}catch (Exception e) {
System.out.println("Exception");
}catch (Throwable t) {
System.out.println("Throwable");
}
finally {
System.out.println("finally");
}
}
public void a(){
b();
}
public void b(){
a();
}
}
package com.exception;
public class Test2 {
public static void main(String[] args) {
int a = 1;
int b = 0;
try {
System.out.println((a/b));
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
}
try{
if (b==0){
throw new ArithmeticException();
}
}
}
}
package com.exception;
public class Tqwe {
public static void main(String[] args) {
try {
new Tqwe().test(1,2);
} catch (ArithmeticException e) {
throw new RuntimeException(e);
}
}
public void test(int a,int b) throws ArithmeticException{
if (b==0){
throw new ArithmeticException();
}
System.out.println(a/b);
}
}
P79 异常03:自定义异常及经验小结


P80 JavaSE总结